Add the contents of one Cursor to another Cursor

前提是你 提交于 2019-12-05 00:10:02

问题


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?

Thanks!!


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/4591068/add-the-contents-of-one-cursor-to-another-cursor

标签

工具导航Map