我的应用程序有一个列表视图.....我如何检索指定的字段值....(在我的情况下昵称和body.see数据库)???????我的意思是我将教皇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();
}
}
我的演示列表视图如下
答案 0 :(得分:0)
如果我理解正确的话。这将是你的解决方案。
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String nickName = ((TextView) v.findViewById(R.id.sender_entry))
.getText().toString();
String BODY = ((TextView) v.findViewById(R.id.body_entry)).getText()
.toString();
}