public void showCityList() { if (!dbManager.isTableExists("storecity.db", "storecity")) { dbManager.execSQL( "storecity.db", "create table storecity(_id integer primary key autoincrement,city varchar(20))"); } // 获取城市列表,显示到listview中 Cursor cursor = dbManager.openQuery("storecity.db", "select _id,city from storecity"); List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>(); while (cursor.moveToNext()) { HashMap<String, Object> hash = new HashMap<String, Object>(); String cityName = cursor.getString(cursor.getColumnIndex("city")); hash.put("cityname", cityName); hash.put("btn1", ""); hash.put("delbtn", "删除"); list.add(hash); } CityListItemSimpleAdapter listadapter = new CityListItemSimpleAdapter( NeedShowWethInfoCityListActivity.this, list, R.layout.need_show_wethinfo_city_listview_item, new String[] {"cityname", "btn1", "delbtn"}, new int[] {R.id.storeListview, R.id.button1, R.id.delbutton, R.id.imageview1}); listView.setAdapter(listadapter); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 对广告信息初始化 AdManager.init(getApplicationContext(), "120511ceb41405ad", "7f2e4c0300e37e06", 30, true); setContentView(R.layout.need_show_wethinfo_city_listview); // 导入已有的数据库 dbManager = new DatabaseManager(getApplicationContext()); db = dbManager.importDatabase(); dbManager.closeDB(db); dcity = this; addCity = (Button) findViewById(R.id.addcity); finishCity = (Button) findViewById(R.id.finishcity); listView = (ListView) findViewById(R.id.storecitylist); showCityList(); addCity.setOnClickListener(new AddCityButtonClickListener()); finishCity.setOnClickListener(new FinishCityButtonClickListener()); }