7,新增的數據庫表在listview中顯示數據庫
private ListView ll; private DBManager dbManager; private static List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); // // ll = (ListView) findViewById(R.id.listView1); // // list.clear(); dbManager = new DBManager(this); List<Person> persons = dbManager.queryMany(); for (Person p : persons) { Map<String, Object> map = new HashMap<String, Object>(); map.put("id", p.get_id()); map.put("name", p.getName()); list.add(map); } SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.detail, new String[] {"name","id" }, new int[] { R.id.text1, R.id.text2 }); ll.setAdapter(adapter);
8,listview事件監聽ide
private static List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); // 注意必定要保證list必定要有數據 ll = (ListView) findViewById(R.id.listView1); ll.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //position 點擊的Item位置,從0開始算 Intent intent=new Intent(addressbook.this,ChatActivity.class); intent.putExtra("name", list.get(position).get("name").toString()); intent.putExtra("id", list.get(position).get("id").toString()); startActivity(intent);//啓動Activity; } });