Question

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 this trick many times, and I am aware of that ... I just want to understand better ! Thanks

Was it helpful?

Solution

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 ORDER BY foo;

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top