MatrixCursor和MergeCursor

1、MatrixCursor创建记录
ContentProvider对外共享数据的时候的query()方法是需要一个cursor的,
但是如果没有数据库,而项目又需要从ContentProvider读取数据的时候怎么办?
更糟糕的是其他方法操作也都是需要cursor的。
此时就需要MatrixCursor了。相当有趣,它相当于为你模拟了一个表。

?
@Override
 
public  Cursor query(Uri uri, String[] projection, String selection,
    String[] selectionArgs, String sortOrder) {
   String[] tableCursor = new  String[] { "name" , "job" , "salary"  };
   MatrixCursor cursor = new  MatrixCursor(tableCursor);
   cursor.addRow( new  Object[] { "1111" , "1111" , "1111"  });
   return  cursor;
}

2、MergeCursor 记录的合并
Cursor c0 = MailboxList.this.managedQuery(
                    EmailContent.Mailbox.CONTENT_URI,
                    MailboxList.this.mListAdapter.PROJECTION,
                    MAILBOX_SELECTION0,
                    new String[] { String.valueOf(mAccountKey) },
                    MailboxColumns.TYPE);
        	Cursor c1 = MailboxList.this.managedQuery(
                        EmailContent.Mailbox.CONTENT_URI,
                        MailboxList.this.mListAdapter.PROJECTION,
                        MAILBOX_SELECTION,
                        new String[] { String.valueOf(mAccountKey) },
                        MailboxColumns.TYPE/* + "," + MailboxColumns.DISPLAY_NAME*/);
        	Cursor c2 = MailboxList.this.managedQuery(
                    EmailContent.Mailbox.CONTENT_URI,
                    MailboxList.this.mListAdapter.PROJECTION,
                    MAILBOX_SELECTION1,
                    new String[] { String.valueOf(mAccountKey) },
                    MailboxColumns.TYPE/* + "," + MailboxColumns.DISPLAY_NAME*/);
               
            Cursor[] cursors = new Cursor[] { c0, c1, c2 };
            Cursor c = new MergeCursor(cursors);


你可能感兴趣的:(android)