Code example for MergeCursor

0
 
    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));
        } 
    } 
}