Reputation: 495
I am using Roman Nurik's SwipeListViewTouchListener
in my app to dismiss the list items.
This is what I am doing:
SwipeListViewTouchListener touchListener2 =
new SwipeListViewTouchListener(
lv,
new SwipeListViewTouchListener.OnSwipeCallback() {
@Override
public void onSwipeLeft(ListView listView, int [] reverseSortedPositions) {
Toast.makeText(MainActivity.this, "LEFT", Toast.LENGTH_SHORT).show();
}
@Override
public void onSwipeRight(ListView listView, int [] reverseSortedPositions) {
}
},
true, // example : left action = dismiss
true); // example : right action without dismiss animation
lv.setOnTouchListener(touchListener2);
lv.setOnScrollListener(touchListener2.makeScrollListener());
Now my problem is how do I remove the dismissed item from the list (something like
customAdapter.remove(position);
and notify the adapter like
customAdapter.notifyDataSetChanged();
Upvotes: 1
Views: 194
Reputation: 11131
try this...
public void onSwipeLeft(ListView listView, int[] reverseSortedPositions) {
Toast.makeText(MainActivity.this, "LEFT", Toast.LENGTH_SHORT).show();
if (reverseSortedPositions != null && reverseSortedPositions.length>0) {
for (int i : reverseSortedPositions) {
customAdapter.remove(i);
}
customAdapter.notifyDataSetChanged();
}
}
Upvotes: 1