Marshmallow (23) + RecyclerView (23.1.0) scrolls the contents of the content above after deleting the element (notifyItemRemoved)

RecyclerView messed up if built using Marshmallow (Android 23) .

I use a RecyclerView populated with a list of elements and when swiped right will delete the element. Removing the item works great. But scrolling through the RecyclerView after deleting the item, create an empty space above the item above the item to be deleted.

I am using a sample project here https://github.com/chrisbanes/cheesesquare with the latest version of Android (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 swipe to remove 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 a removeItemAt method to remove an item

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

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

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

Let me know if anyone had this problem.

+5
source share
1 answer

I also ran into this problem. This seems to be just a problem with lib 23.1.0 support. I do not encounter a problem using com.android.support:recyclerview-v7:23.0.1. I sent this error to Google https://code.google.com/p/android/issues/detail?id=191960

It seems that the fix is ​​already on the way: https://code.google.com/p/android/issues/detail?id=190500

+3
source

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


All Articles