androidlistviewandroid-cursoradaptermergecursor

Android ListView not refreshing after change cursor


the following code is used to populate an endless ListView. When the user reach the end of the list, the app call the async task to get more items, then on post execute the new cursor is returned and merged with the previous. The problem is this code does not work on ICS and Jelly Bean, but works on Froyo and Gingerbread. On ICS and JellyBean the listview gets empty, but if you log cursor size you get the size of the merged 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);  

Solution

  • Ok, i found a solution, seems an ungly solution, but it works. On my research all the problems seemed to address to an issue after Honeycumb, so i changed the API Level to 11, to get swapCursor available, and then, on 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!
    Best regards.
    Rodrigo