Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add the contents of one Cursor to another Cursor

I want to join two cursors so that the contents of the second Cursor shall also appear in first Cursor after joining.

Precisely here is my code,

public final Uri AllImage_URI_Int = MediaStore.Images.Media.INTERNAL_CONTENT_URI;
public final Uri AllAudio_URI = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
cContentList = managedQuery(AllImage_URI_Int, null, null, null, MediaStore.Images.ImageColumns.TITLE);
cList_Int = managedQuery(AllImage_URI, null, null, null, MediaStore.Images.ImageColumns.TITLE);

Should i use the CursorJoiner in this case?

I want to pass this Cursor to SimpleListAdapter? How can i join those two cursors?

like image 542
Vamsi Avatar asked Jan 04 '11 06:01

Vamsi


2 Answers

Maybe you can use a MergeCursor wrapper to merge your two Cursors into a new one, and pass it to your Adapter.

like image 196
chengbo Avatar answered Nov 14 '22 23:11

chengbo


well, i solved it myself and working, extendeb by AbstractCursor, heres the code,

private final int ROWCACHESIZE = 64;
private int mRowNumCache[] = new int[ROWCACHESIZE];
private int mCursorCache[] = new int[ROWCACHESIZE];
private int mCurRowNumCache[][];
private int mLastCacheHit = -1;

public SortCursor(Cursor[] cursors, String sortcolumn)
{
    mCursors = cursors;

    int length = mCursors.length;
    mSortColumns = new int[length];
    for (int i = 0 ; i < length ; i++) {
        if (mCursors[i] == null) continue;

        mCursors[i].moveToFirst();

        // We don't catch the exception
        mSortColumns[i] = mCursors[i].getColumnIndexOrThrow(sortcolumn);
    }
    mCursor = null;
    String smallest = "";
    for (int j = 0 ; j < length; j++) {
        if (mCursors[j] == null || mCursors[j].isAfterLast())
            continue;
        String current = mCursors[j].getString(mSortColumns[j]);
        if (mCursor == null || current.compareToIgnoreCase(smallest) < 0) {
            smallest = current;
            mCursor = mCursors[j];
        }
    }

    for (int i = mRowNumCache.length - 1; i >= 0; i--) {
        mRowNumCache[i] = -2;
    }
    mCurRowNumCache = new int[ROWCACHESIZE][length];
}
like image 44
Vamsi Avatar answered Nov 15 '22 00:11

Vamsi