开发者

Listview from multiple tables?

I'd like to populate a listview from 2 tables. Anyone know how I can achieve this? Currently what I have looks like but it only works with one adapter:

   private void populate() {
        todoCursor = dbNotes.getTodoKey();
        startManagingCursor(todoCursor);
        todo = 
             new SimpleCursorAdapter(
               this,
               R.layout.todo_list, 
               todoCursor,
         开发者_高级运维      new String[] {databaseHelper.DB_COLUMN_TODO_KEYS},
               new int[] {R.id.textTodo});
        setListAdapter(todo);
    }

    private void fillData(int i) {
        Cursor notesCursor = dbNotes.retrieveAll(i, "=0");
        startManagingCursor(notesCursor);
        notes = 
             new SimpleCursorAdapter(
               this,
               R.layout.list_item, 
               notesCursor,
               new String[] {databaseHelper.DB_COLUMN_SUBJECT, databaseHelper.DB_COLUMN_TIME, databaseHelper.DB_COLUMN_MESSAGE, databaseHelper.DB_COLUMN_DOW, databaseHelper.DB_COLUMN_MD},
               new int[] {R.id.text1, R.id.text2, R.id.text3, R.id.textDay, R.id.textDayOfWeek});
        setListAdapter(notes);
    }


I'd like to populate a listview from 2 tables. Anyone know how I can achieve this?

You haven't exactly explained what you mean by "populate a listview from 2 tables".

So, depending on your definition, you could:

  • Use a join to create a single result set from both tables
  • Use my MergeCursor to concatenate adapters on your two result sets into a single adapter
  • Assemble a single MatrixCursor from your disparate parts that you then put into the list

There are probably other solutions as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜