SQlite primary key field name & CursorAdapter subclasses

爱⌒轻易说出口 提交于 2019-12-25 04:19:10

问题


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


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

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



来源:https://stackoverflow.com/questions/23068199/sqlite-primary-key-field-name-cursoradapter-subclasses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!