Android MatrixCursor - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android MatrixCursor class.

This code example shows how to use the following methods:newRow
            } 
        } 
    } 
 
    private void setData(Cursor groups) {
        MatrixCursor psuedoGroups = new MatrixCursor(new String[] { "_id", "name" });
        psuedoGroups.newRow().add(-1).add("All Contacts");
        psuedoGroups.newRow().add(-2).add("Favorites");
        mAdapter.changeCursor(new MergeCursor(new Cursor[] { psuedoGroups, groups }));
    } 
 
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if (id == GROUP_ID_ALL_CONTACTS) {
            mController.onAllContactsSelected();
        } else if (id == GROUP_ID_FAVORITES) {
            mController.onFavoritesSelected();
        } else { 
            Cursor cursor = (Cursor) mAdapter.getItem(position);
            mController.onGroupSelected(cursor.getString(GroupsListLoader.COLUMN_TITLE));
        } 
7
CodeRank
This code example shows how to use the following methods:addRow
import com.android.ex.chips.RecipientEntry; 
 
public class RecipientAlternatesAdapterTest extends AndroidTestCase {
 
    public void testRemoveDuplicateDestinations() { 
        MatrixCursor c = new MatrixCursor(Queries.EMAIL.getProjection());
        Cursor result;
 
        // Test: Empty input 
        assertEquals(0, RecipientAlternatesAdapter.removeDuplicateDestinations(c).getCount());
 
 
        // Test: One row 
        addRow(c, "a", "1@android.com", 1, "home", 1000, 2000, "x", 0);
 
        result = RecipientAlternatesAdapter.removeDuplicateDestinations(c);
        assertEquals(1, result.getCount());
        assertRow(result, 0, "a", "1@android.com", 1, "home", 1000, 2000, "x", 0);
 
        // Test: two unique rows, different destinations 

6
CodeRank
This code example shows how to use the following methods:addRow
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         
        requestCursor(); 
		 
		setListAdapter(new ItemSectionAdapter(this, mCursor));
    } 
     
    private void requestCursor() { 
		mCursor = new MatrixCursor(new String[] { "_id", "Section", "Name" });
		 
		mCursor.addRow(new String []{ "3","Section 1", "Item 1" });
		mCursor.addRow(new String []{ "2", "Section 1", "Item 2" });
		mCursor.addRow(new String []{ "4","Section 2", "Item 3" });
		mCursor.addRow(new String []{ "5","Section 2", "Item 4" });
		mCursor.addRow(new String []{ "6","Section 2", "Item 5" });
		mCursor.addRow(new String []{ "7","Section 2", "Item 6" });
		mCursor.addRow(new String []{ "8","Section 2", "Item 7" });
		mCursor.addRow(new String []{ "9","Section 3", "Item 8" });
		mCursor.addRow(new String []{ "9","Section 3", "Item 9" });

6
CodeRank
This code example shows how to use the following methods:moveToFirst, addRow
     * @param name the name to insert in the first column of the cursor 
     * @param alternateName the alternate name to insert in the second column of the cursor 
     * @return the newly created cursor 
     */ 
    private Cursor createCursor(String name, String alternateName) {
        MatrixCursor cursor = new MatrixCursor(new String[]{"Name", "AlternateName"});
        cursor.moveToFirst();
        cursor.addRow(new Object[]{name, alternateName});
        return cursor;
    } 
} 
7
CodeRank
This code example shows how to use the following methods:moveToFirst, addRow
import java.util.Set; 
 
public class FolderPropertiesTests extends AndroidTestCase {
 
    private static Cursor buildCursor(String[] columns, Object... values) {
        MatrixCursor c = new MatrixCursor(columns, 1);
        c.addRow(values);
        c.moveToFirst();
        return c;
    } 
 
    /** 
     * Tests of the syncronization of array and types of the display folder names 
     */ 
    public void testGetDisplayName() { 
        Context context = getContext();
        FolderProperties fp = FolderProperties.getInstance(context);
 
        assertEquals(
                    context.getString(R.string.mailbox_name_display_inbox),
7
CodeRank
This code example shows how to use the following methods:addRow
 
    /** 
     * Creates a dummy cursor to represent the "Searching directory..." item. 
     */ 
    private Cursor createLoadingCursor() {
        MatrixCursor cursor = new MatrixCursor(new String[]{SEARCHING_CURSOR_MARKER});
        cursor.addRow(new Object[]{""});
        return cursor;
    } 
 
    public void onPartitionLoadFinished( 
            CharSequence constraint, int partitionIndex, Cursor cursor) {
        if (partitionIndex < getPartitionCount()) {
            DirectoryPartition partition = (DirectoryPartition) getPartition(partitionIndex);
 
            // Check if the received result matches the current constraint 
            // If not - the user must have continued typing after the request 
            // was issued 
            if (partition.loading && TextUtils.equals(constraint, partition.constraint)) {
                partition.loading = false;
6
CodeRank
This code example shows how to use the following methods:addRow
			return mConstraint;
		} 
	} 
 
	private static Cursor cursorWithHeader(Cursor cursor) {
		MatrixCursor header = new MatrixCursor(new String[]{"_id"}, 1);
		header.addRow(new Object[] { new Long(-1)});
		return new MergeCursor(new Cursor[] {header, cursor});
	} 
} 
6
CodeRank
This code example shows how to use the following methods:addRow
            if (uri.toString().equals("content://" + mAuthority + "/directories")) {
                // Should tolerate multiple queries. 
                mResponse.moveToPosition(-1);
                return mResponse;
            } else if (uri.toString().startsWith("content://" + mAuthority + "/contacts")) {
                MatrixCursor cursor = new MatrixCursor(
                        new String[] { "projection", "selection", "selectionArgs", "sortOrder",
                                "accountName", "accountType"}); 
                cursor.addRow(new Object[] {
                    Lists.newArrayList(projection).toString(),
                    selection,
                    Lists.newArrayList(selectionArgs).toString(),
                    sortOrder,
                    uri.getQueryParameter(RawContacts.ACCOUNT_NAME),
                    uri.getQueryParameter(RawContacts.ACCOUNT_TYPE),
                }); 
                return cursor;
            } else if (uri.toString().startsWith(
                    "content://" + mAuthority + "/aggregation_exceptions")) {
                return new MatrixCursor(projection);
6
CodeRank
This code example shows how to use the following methods:
        assert(uri.getPathSegments().size() == 1);
 
        // In this sample, we only update the content provider individually for each row with new 
        // temperature values. 
        final int index = Integer.parseInt(uri.getPathSegments().get(0));
        final MatrixCursor c = new MatrixCursor(
                new String[]{ Columns.ID, Columns.DAY, Columns.TEMPERATURE });
        assert(0 <= index && index < sData.size());
        final WeatherDataPoint data = sData.get(index);
        data.degrees = values.getAsInteger(Columns.TEMPERATURE);
 
        // Notify any listeners that the data backing the content provider has changed, and return 
        // the number of rows affected. 
        getContext().getContentResolver().notifyChange(uri, null);
        return 1; 
    } 
 
} 
6
CodeRank
This code example shows how to use the following methods:addRow
		 */ 
		static void addRowToCursor(MatrixCursor cursor, boolean isAuthorized) {
			Object[] values = new Object[COLUMN_NAMES.length];
			values[0] = new Integer(isAuthorized ? 1 : 0);
 
			cursor.addRow(values);
		} 
 
		private AuthorizationColumns() { 
		} 
	} 
} 
6
CodeRank

Related Android MatrixCursor Questions & Answers:

See Code Examples for Android MatrixCursor Methods: