5

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?

0

2 Answers 2

17

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

0
3

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];
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.