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.
source share