SimpleCursorAdapter, Move the cursor at API level below 11

Trying to implement LoaderManager + CursorLoader.

In the onFinish adapter, the adapter should change 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 with a level 11 API.

So, how do I change the cursor in the Android 10 API?

+6
source share
2 answers

If you follow the Android Studio suggestion for wrapping and swapCursor an explanation that the old cursor was not 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(); } } 
0
source

Source: https://habr.com/ru/post/918064/


All Articles