0

我的应用程序有一个列表视图.....我怎样才能检索指定的字段值....(在我的情况下是昵称和正文。查看数据库)???????我的意思是我会弹出昵称和正文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();


}

}

我的演示列表视图如下

在此处输入图像描述

4

1 回答 1

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();
    }
于 2012-07-05T15:34:59.977 回答