Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Marshmallow(23) + RecyclerView(23.1.0) scrolling messes up content above after item removed (notifyItemRemoved)

The RecyclerView messed up if build with Marshmallow (Android 23) .

I using RecyclerView filled with list of items and when swiped right will remove the item. Removing the item works fine. But scrolling up on the RecyclerView after removing an item, creates blank space on the item above the one removed.

I'm using the sample project here https://github.com/chrisbanes/cheesesquare with the latest android version (Marshmallow)

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
    applicationId "com.support.android.designlibdemo"
    minSdkVersion 9
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
 }
}

And add the swipe to dismiss code

private void setItemDismiss(final RecyclerView recyclerView) {
    ItemTouchHelper.SimpleCallback simpleCallback = new ItemTouchHelper.SimpleCallback(ItemTouchHelper.RIGHT, ItemTouchHelper.RIGHT) {
        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
            return false;
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
            int position = viewHolder.getAdapterPosition();
            ((SimpleStringRecyclerViewAdapter)recyclerView.getAdapter()).removeItemAt(position);
        }
    };

    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleCallback);
    itemTouchHelper.attachToRecyclerView(recyclerView);
}

The adapter has the method removeItemAt to remove item

public void removeItemAt(int position) {
        mValues.remove(position);
        notifyItemRemoved(position);
    }

Everything works good if compileSdkVersion 22 and targetSdkVersion 22 with com.android.support:recyclerview-v7:22.2.0

Check this : https://www.youtube.com/watch?v=AbiFzDzFwjo&feature=youtu.be

Let me know if anyone had this issue.

like image 669
Libin Avatar asked Oct 18 '22 23:10

Libin


1 Answers

I have encountered this issue as well. It appears to be only a problem with support lib 23.1.0. I do not encounter the problem using com.android.support:recyclerview-v7:23.0.1. I have submitted this bug to Google https://code.google.com/p/android/issues/detail?id=191960

Looks like the fix is on its way: https://code.google.com/p/android/issues/detail?id=190500

like image 140
GFred Avatar answered Nov 02 '22 11:11

GFred