日期:2014-05-16 浏览次数:20560 次
ListView lv = (ListView) this.findViewById(R.id.listView); SimpleCursorAdapter sca = new SimpleCursorAdapter(this, R.layout.listmsg, cur, new String[]{"_id","name","val"}, new int[]{R.id.textViewID,R.id.textViewName,R.id.textViewVal}); lv.setAdapter(sca);
Cursor cur = dao.show();
public Cursor show(){ db = dbh.getReadableDatabase(); Cursor cur = db.query("person",null, null, null, null, null, null); // cur.close(); return cur; }
lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub selectedID = position; int i = sca.getCursor().getColumnIndex("_id"); // System.out.println("id:"+cur.getString(i)); delID = cur.getString(i); } });
delete.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub System.out.println(selectedID+1); dao.redelete(delID); cur.requery(); sca.notifyDataSetChanged(); selectedID = 99999; } });
public void redelete(String s){ db = dbh.getWritableDatabase(); db.delete("person", "_id=?", new String[]{s}); }