我的应用程序有一个列表视图.....我怎样才能检索指定的字段值....(在我的情况下是昵称和正文。查看数据库)???????我的意思是我会弹出昵称和正文listView 中的文本....怎么可能
我的代码 ListView.java
public class ListView extends ListActivity {
SQLiteDatabase messagedb;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.my_list);
messagedb=ListView.this.openOrCreateDatabase("message",0, null);
messagedb.execSQL(
"CREATE TABLE IF NOT EXISTS tab2(" +
" _id INTEGER PRIMARY KEY," +
" nickname varchar,sender INT(13),body varchar)");
Cursor cur = messagedb.rawQuery("select rowid as _id, nickname, body from tab2", null);
String[] from = new String[] { "nickname", "body" };
int[] to = new int[] { R.id.sender_entry, R.id.body_entry};
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.my_list_entry, cur, from, to);
this.setListAdapter(mAdapter);
messagedb.close();
}
}
我的演示列表视图如下