SimpleCursorAdapter返回空数据

时间:2013-01-14 19:49:56

标签: android listview android-listview simplecursoradapter

当我尝试通过SimpleCursorAdapter将数据从数据库放入ListView时,会显示ListView的行,但它们是空的。

像:

[ _ __ _ __ _ ____

[ _ __ _ __ _ ____

[ _ __ _ __ _ ____

而不是:

[TEXT]

[TEXT]

[TEXT]

我的代码:

    db = provider.getReadableDatabase();
    String[] columns = {"_id", "Title"};
    Cursor cursor = db.query(NotificationsProvider.TABLE_NAME, columns, null, null, null, null, null);
    Log.d(TAG, "COUNT: "+cursor.getCount());
    String[] clm = {"Title"};
    int[] to = {android.R.id.list};
    cursorAdapter = new SimpleCursorAdapter(this,
            android.R.layout.simple_list_item_1,
            cursor, clm, to, 0);

    setListAdapter(cursorAdapter);

谢谢!

1 个答案:

答案 0 :(得分:1)

您只是使用了错误的ID,请尝试:

int[] to = {android.R.id.text1};

(您可以自己查看simple_list_item_1.xml以验证相应的ID。)