How to implement a content provider with more than one table?

后端 未结 3 1939
傲寒
傲寒 2021-02-06 19:29

update: looking at \"vnd.android.cursor.dir/vnd.google.note\" and \"vnd.android.cursor.item/vnd.google.note\" it seemed to me as thoug

3条回答
  •  盖世英雄少女心
    2021-02-06 20:26

    Excuse me, but I don't understand your question.

    ContentProvider is designed (a one of it's aims)to wrap access to your tabels. Design of database schema is up to you.

    Generally, you need to:

    1. Define your tables/ It should be made by execution of sql command in class which extends SQLiteOpenHelper
    2. Define an uri for them
    3. Define a logic for queries to this tables as it was made for NOTE_ID

    Update For JOIN operations SQLiteQueryBuilder is usually used. In setTables() you need to write names of tables with JOIN clause, e.g.

    .setTables(NoteColumns.TABLENAME +
                " LEFT OUTER JOIN " + TopicColumns.TABLENAME + " ON " +
                NoteColumns.ID + " = " + TopicColumns.ID);
    

提交回复
热议问题