Skip to content
Lucio P. Cossio edited this page Mar 6, 2015 · 5 revisions

If you enable Swipe To Dismiss functionality the user will be able to press down on a list item, and swipe it to the left or right to dismiss it. Before you enable Swipe To Dismiss you need to set up an OnDismissCallback (and, if you wish to, undo functionallity) as described here.

Afterwards enable Swipe To Dismiss with enableSwipeToDismiss().

By default the user can swipe out list items to both directions. Use setSwipeDirection to limit the user to one direction.

By default the whole list item will be swiped by the user. If you only want to swipe a part of the list item (e.g. you want a view behind it, explaining, the swiping) you can use setSwipeLayout. Pass an id from R.id to the method. Each time the user starts swiping, EnhancedListView will try to find a View with that id in the list item's view. If it does so, only that view will be swiped and not the whole list item view.

Swipe only specific items

If you want to exclude items from swipe (or only swipe specific items) - e.g. because you have header items in your list - you can set an OnShouldSwipeCallback. This will be called when the user tries to swipe an item and your implementation must either return true (the item will be swiped) or false (no swipe for that item).

Example:

listView.setShouldSwipeCallback(new OnShouldSwipeCallback() {
  @Override
  public boolean onShouldSwipe(EnhancedList lv, int position) {
    // Only allow even items to be swiped (for whatever reason)
    return position % 2 == 0;
  }
});

Change swipe threshold

By default a swipe begins if the user swiped at least 32dp. This threshold should give a good balance between detect swipe to dismisses in a good way but not canceling scrolling all the time because the user accidentally swiped instead of scrolling. If you want to change this, create a dimen resource with the name elv_touch_slop in your app to overwrite the default.

Clone this wiki locally