Skip to content Skip to sidebar Skip to footer

Sqlite Primary Key Field Name & Cursoradapter Subclasses

Why do CursorAdapter subclasses requires the primary key to be necessarily _id ? Isn't there a method to override, or something like that, to change this behaviour ? I have read th

Solution 1:

Why does CursorAdapter subclasses requires the primary key to be necessarily _id ?

It turns around and provides that value in various places, such as the long id value in getView().

Isn't there a method to override, or something like that, to change this behaviour ?

No, sorry. If you do not have a suitable column, just add ROWID AS _ID to your list of columns to return in rawQuery():

SELECT ROWID AS _id, foo, bar FROM really_important_table ORDERBY foo;

ROWID is automatically added to all SQLite tables by default, and is a unique integer, which fits the _id requirements nicely.

Post a Comment for "Sqlite Primary Key Field Name & Cursoradapter Subclasses"