SimpleCursorAdapter, Swapping cursor in API level below 11
Asked Answered
E

2

6

Trying to implement LoaderManager + CursorLoader.

In onFinish method adapter should swap its cursor

  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    // Swap the new cursor in.  (The framework will take care of closing the
    // old cursor once we return.)
    mAdapter.swapCursor(data);
  }

But swapCursor is available since API Level 11.

So how should I swap cursor in android API 10 ?

Embonpoint answered 14/6, 2012 at 7:21 Comment(0)
R
0

If you follow Android Studio suggestion to wrap and swapCursor's explanation that the old cursor wasn't close, using android.widget.CursorAdapter, you get:

public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mAdapter.swapCursor(data);
    } else {
        Cursor oldCursor = mAdapter.getCursor();
        mAdapter.changeCursor(data);
        oldCursor.close();
    }
}
Reasonless answered 17/2, 2017 at 14:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.