Reputation: 137
I'm using this library to make a listview with swipe to dismiss feature.
I am using an ArrayAdapter and using this code to create a swipe to dismiss listener
SwipeDismissListViewTouchListener touchListener =
new SwipeDismissListViewTouchListener(
listView,
new SwipeDismissListViewTouchListener.DismissCallbacks() {
@Override
public boolean canDismiss(int position) {
return true;
}
@Override
public void onDismiss(ListView listView, int[] reverseSortedPositions) {
for (int position : reverseSortedPositions) {
mAdapter.remove(mAdapter.getItem(position));
}
mAdapter.notifyDataSetChanged();
}
});
listView.setOnTouchListener(touchListener);
// Setting this scroll listener is required to ensure that during ListView scrolling,
// we don't look for swipes.
listView.setOnScrollListener(touchListener.makeScrollListener());
But every time trying to swipe it seems like it worked but then the item comes back.
The log cat doesn't throw me any exception.
Did anybody had this error before? please help.
Upvotes: 3
Views: 1575
Reputation: 119
I faced the same issue when I used swipe-to-dismiss by Roman Nurik. Create your own remove method in adapter:
public void remove(int position) {
yourList.remove(position);
}
and you should call it like:
@Override
public void onDismiss(ListView listView, int[] reverseSortedPositions) {
for (int position : reverseSortedPositions) {
mAdapter.remove(position);
}
mAdapter.notifyDataSetChanged();
}
Upvotes: 4