Code example for MatrixCursor

Methods: addRow

0
    private static class SampleMockContentProvider extends MockContentProvider {
        @Override 
        public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
            // クエリ結果のモック作成 
            // MatrixCursor を用いてデータをモックする 
            MatrixCursor cursor = new MatrixCursor(projection);
            cursor.addRow(new String[] {"1", "KeithYokoma"});
            cursor.addRow(new String[] {"2", "HogeFugao"});
            cursor.addRow(new String[] {"3", "HiyoHiyo"});
            return cursor;
        } 
 
        @Override 
        public void attachInfo(Context context, ProviderInfo info) {
        } 
    } 
 
    private static class SampleMockContentResolver extends MockContentResolver {
        public SampleMockContentResolver(Context context) {
            // モックの ContentProvider へアクセスしに行くよう設定する 
            ContentProvider provider = new SampleMockContentProvider();