is it possible to populate a listview based on a row Id from a custom cursor adapter. I keep getting an error “illegalArguementException column: _id does not exist”. but the database has it and is already being used correctly. I don’t know what to do, because I would need to populate different listviews from the same database and i don’t want to have to create multiple database which will still have the same column names. Any ideas will be greatly appreciated. thanks
HERE is the database code is being cold:
public Cursor retrieveItemRow(long Id){
open();
String[] Columns = new String[] {TITLE,DATE, TIME};
Cursor row = db.query(true,DATABASE_TABLE, Columns, KEY_ID +"=" +Id, null, null, null, null,null);
if(row != null){
row.moveToNext();
return row;
}
return row;
}
Here is a method i am trying to call it in:
public void fillRowData(long Id) {
Cursor cursor = adapter.retrieveRow(id);
startManagingCursor(cursor);
String[] from = new String[]{DBAdapter.TITLE, DBAdapter.DATE, DBAdapter.TIME};
int[] to = new int[]{R.id.Name, R.id.Date, R.id.Time};
customCursor items = new customCursor(this, R.layout.viewlist, cursor, from, to);
setListAdapter(items);
}
Make sure you include _id in the SELECT statement represented by the Cursor you pass into your adapter. For example, if I were using the
SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to), myCursor cwould originate with something like “SELECT _id, name FROM users;”.From the Notepad Tutorial:
The tutorial defines a method in the database helper class that returns all of the
Noteobjects. Essentially they’re usingSQLiteDatabase‘squerymethod that returns aCursorobject. The query’s select string is where you should include the _id column.So in your case, you need to add
KEY_IDto yourColumnsString array variable, because those are the columns that are included in your select statement (db.query()). This is also hinted at in the CursorAdapter documentation: