Skip to content

A mini-library/sample code that shows how to make a ListView support the swipe-to-dismiss Android UI pattern with feedback.

License

Notifications You must be signed in to change notification settings

torryharris/TH-SwipeToDismiss

 
 

Repository files navigation

TH-SwipeToDismiss

A mini-library/sample code that shows how to make a ListView support the swipe-to-dismiss Android UI pattern with feedback.

alt text

How to use:

  1. Add the SwipeListViewTouchListener.java to your project.

  2. 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);
    
  3. Set the touchListener to your listView:

     listView.setOnTouchListener(touchListener); 
     listView.setOnScrollListener(touchListener.makeScrollListener());
    
  4. Include the remove(int position) method in your adapter as shown in CustomAdapter.java.

  5. Set your desired color by changing the color in SwipeListViewTouchListener.java

     mDownView.setBackgroundColor(Color.GREEN);
    

##Demo Get it on Google Play

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.

About

A mini-library/sample code that shows how to make a ListView support the swipe-to-dismiss Android UI pattern with feedback.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%