TH-SwipeToDismiss
A mini-library/sample code that shows how to make a ListView
support the swipe-to-dismiss Android UI pattern with feedback.
How to use:
-
Add the
SwipeListViewTouchListener.java
to your project. -
Add the
SwipeListViewTouchListner
to your listView as shown below:SwipeListViewTouchListener touchListener = new SwipeListViewTouchListener( listView, new SwipeListViewTouchListener.OnSwipeCallback() { @Override public void onSwipeLeft(ListView listView, int[] reverseSortedPositions) { if (reverseSortedPositions != null && reverseSortedPositions.length > 0) { for (int i : reverseSortedPositions) { customAdapter.remove(i); } customAdapter.notifyDataSetChanged(); } } @Override public void onSwipeRight(ListView listView, int[] reverseSortedPositions) { if (reverseSortedPositions != null && reverseSortedPositions.length > 0) { for (int i : reverseSortedPositions) { customAdapter.remove(i); } customAdapter.notifyDataSetChanged(); } } }, true, true);
-
Set the touchListener to your listView:
listView.setOnTouchListener(touchListener); listView.setOnScrollListener(touchListener.makeScrollListener());
-
Include the
remove(int position)
method in your adapter as shown inCustomAdapter.java
. -
Set your desired color by changing the color in SwipeListViewTouchListener.java
mDownView.setBackgroundColor(Color.GREEN);
Are you using this framework?
If you are using this framework in your app, please feel free to add your app to the wiki
See the original Roman Nurik's Android-SwipeToDismiss.