https://github.com/evant/itemtouchhelperclearviewissue
Issue with using ItemTouchHelper and an ItemDecoration
https://github.com/evant/itemtouchhelperclearviewissue
Last synced: 10 days ago
JSON representation
Issue with using ItemTouchHelper and an ItemDecoration
- Host: GitHub
- URL: https://github.com/evant/itemtouchhelperclearviewissue
- Owner: evant
- Created: 2015-06-04T19:07:09.000Z (about 11 years ago)
- Default Branch: main
- Last Pushed: 2020-06-14T22:48:50.000Z (about 6 years ago)
- Last Synced: 2025-02-23T18:32:16.837Z (over 1 year ago)
- Language: Java
- Size: 76.2 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ItemTouchHelperClearViewIssue
Issue with using ItemTouchHelper and an ItemDecoration
Swipe away items from the top to the bottom, you'll see that they aren't acutally removed from the view hierarchy, (the trash can will still be there). If you comment out the line which adds an ItemDecoration, it works correctly.
## Solution
As suggested in the [issue](https://code.google.com/p/android/issues/detail?id=175798) `invalidateItemDecorations()` needs to be called after the item is removed, because the ItemDecoration is based on the item's positions in the list.
```java
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int state) {
...
viewHolder.itemView.post(new Runnable() {
@Override
public void run() {
recyclerView.invalidateItemDecorations();
}
});
}
```