daimajia / daimajia/AndroidSwipeLayout

RecyclerView Delete Element on Swipe

Open
#201 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
12.3k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

I've noticed some strange issues with Swiping to Delete elements. To make this easy, I've used the sample to show case my issue. If I swipe to delete an element, the element below stays in the delete state. Basically, it looks like the bottom layout stays over the next element.

Here's what happens in the sample:
Original Load:
![screenshot_2015-08-10-12-25-39](https://cloud.githubusercontent.com/assets/13733982/9176815/5d731e58-3f42-11e5-9742-33efed1f34d5.png)

Swipe Left on Top Element (Alabama):

![screenshot_2015-08-10-12-26-23](https://cloud.githubusercontent.com/assets/13733982/9176814/5d71e22c-3f42-11e5-9cfb-4a810a38a717.png)

Notice that Alabama gets deleted, but Alaska (the element below) still has the bottom view open. I can't figure out how to prevent this behavior. To try out the code, simply replace the OnCreateViewHolder from the sample with the following (has some logging):

```
@Override
public SimpleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_item, parent, false);
final SimpleViewHolder viewHolder = new SimpleViewHolder(view);

SwipeLayout swipeLayout = viewHolder.swipeLayout;

swipeLayout.addSwipeListener(new SimpleSwipeListener() {

@Override
public void onOpen(SwipeLayout layout) {

Log.d("Swiped Opened", viewHolder.textViewData.getText().toString());
int position = mDataset.indexOf(viewHolder.textViewData.getText());
mItemManger.removeShownLayouts(viewHolder.swipeLayout);
mDataset.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, mDataset.size());
mItemManger.closeAllItems();

Log.d("Swipe Deleted", viewHolder.textViewData.getText().toString() + String.valueOf(position));
//Toast.makeText(view.getContext(), "Deleted " + viewHolder.textViewName.getText().toString() + "!", Toast.LENGTH_SHORT).show();

}

});

return viewHolder;
}
```

I noticed when I remove the notifyItemRangeChanged(...), the situation looks a little better, but it turns out random elements still look like Delete Item. Any thoughts/suggestions?

Edit: Ignore the multiple/single mode. Looks like this happens regardless :(

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.