Android ListView does not update after cursor changes

The following code is used to populate an infinite ListView. When the user reaches the end of the list, the application will call the async task to get more elements, and then in post, execute a new cursor returns and merges with the previous one. The problem is that this code does not work on ICS and Jelly Bean, but it works on Froyo and Gingerbread. In ICS and JellyBean, the listview is empty, but if you register the cursor size, you get the size of the combined cursor.

Cursor[] cursors = new Cursor[2]; //actual cursor cursors[0] = resourceCursor.getCursor(); //new cursor returned by async task cursors[1] = result; MergeCursor mergeCursor = new MergeCursor(cursors); resourceCursor.changeCursor(mergeCursor); 
+4
source share
1 answer

Ok, I found a solution, it seems like a solution, but it works. In my research, all the problems seemed to be related to the problem after Honeycumb, so I changed the API level to 11 to get swapCursor, and then in my code:

 Cursor[] cursors = new Cursor[2]; //actual cursor cursors[0] = resourceAdapterCursor.getCursor(); //new cursor returned by async task cursors[1] = result; MergeCursor mergeCursor = new MergeCursor(cursors); if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD){ resourceAdapterCursor.swapCursor(mergeCursor); } else { resourceAdapterCursor.changeCursor(mergeCursor); } 

Thanks!
Sincerely. Rodrigo

+1
source

All Articles