【发布时间】:2015-03-06 19:48:23
【问题描述】:
我有两张表 atm,用户和便笺。我正在尝试检索属于用户的数据。因此,所有要列出的数据都必须归原始用户所有,并且只显示给他。我在 Databasehelper 中制作了我的表。 我创建了一个控制笔记表的新类。在 listNotes() 中,我想遍历光标行并获取用户拥有的所有数据。我的查询正确吗?
// Listing all notes
public Cursor listNotes() {
Cursor c = db.query(help.NOTE_TABLE, new String[]{help.COLUMN_TITLE,help.COLUMN_BODY, help.COLUMN_DATE}, null, null, null, null, null);
if (c != null) {
c.moveToFirst();
}
db.close();
return c;
}
然后我想在列表视图中显示收集到的光标数据
public void populateList(){
Cursor cursor = control.listNotes();
getActivity().startManagingCursor(cursor);
//Mapping the fields cursor to text views
String[] fields = new String[]{help.COLUMN_TITLE,help.COLUMN_BODY, help.COLUMN_DATE};
int [] text = new int[] {R.id.item_title,R.id.item_body, R.id.item_date};
adapter = new SimpleCursorAdapter(getActivity(),R.layout.list_layout,cursor, fields, text,0);
//Calling list object instance
listView = (ListView) getView().findViewById(android.R.id.list);
adapter.notifyDataSetChanged();
listView.setAdapter(adapter);
}
【问题讨论】:
标签: android android-fragments android-listview android-sqlite