Android sqlite数据检索器

时间:2013-06-17 07:01:20

标签: java android sqlite

SQLiteDatabase db = new MySQLiteOpenHelper(this).getReadableDatabase();
    String table = SQLContract.tables.Score.TABLE_NAME;
    String [] columns = {SQLContract.tables.Score._ID,SQLContract.tables.Score.COLUMN_NAME_player_Name,SQLContract.tables.Score.COLUMN_NAME_Score};
    String selection = null;
    String [] selectionArgs = null;
    String groupBy = null;
    String having = null;
    String orderBy = null;
    Cursor c = db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy);
    int [] to = {android.R.id.text1};

    String [] from = { SQLContract.tables.Score.COLUMN_NAME_player_Name};
    SimpleCursorAdapter sca = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, c, from, to, SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    setListAdapter(sca);

我想在列表视图上显示数据bt这段代码不起作用......有人帮忙解决这个问题.... ???

这是错误(1)没有这样的列:_id

1 个答案:

答案 0 :(得分:0)

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

为其分配您的主键列的值"_id"

你赞成的方式

String [] from = { SQLContract.tables.Score.COLUMN_NAME_player_Name};

from中显示您要在列表中显示的值。

To中绑定要在单击列表项时进行重新计算的值。

此外 重命名primary key ColumnName to "_id"您没有延长BaseAdapter,因此您必须坚持使用already defined column name "_id"