Simple Cursor Adapter problem

后端 未结 3 1958
北荒
北荒 2021-01-25 08:01

Here is my code for a simple cursor adapter.

public class CursorList extends ListActivity {
/** Called when the activity is first created. */
@Override
public vo         


        
相关标签:
3条回答
  • 2021-01-25 08:25

    You need to include the table _id in the projection. the list cursor adapter needs the _id to keep track of the rows. you don't have to actually display it anywhere or use it but the cursor needs to contain that column. also a primary key column named _id is mandatory in every android table.

    0 讨论(0)
  • 2021-01-25 08:26

    Why does it give an error that column '_id' doesn't exist? Is it a necessary column which we have to have in our tables?

    Yes, if you want to use your database information in a cursor adapter. The adapter uses it for internal purposes. Your table must have an '_id' column, and you must select it in your query (so it is in the Cursor result set). You do not have to actually display it in your ListView.

    Revised for Posterity

    Instead of actually adding the '_id' column, you can SELECT your own 'id' column as '_id', and it will work just the same.

    0 讨论(0)
  • 2021-01-25 08:50

    Write Cursor related code in try catch block.Your problem will be solved.Check when created table you typed different column rather than '_id'

    0 讨论(0)
提交回复
热议问题