Shared publicly  - 

OK, seems from the last post that lots of folks are interested in an early look at swipe-to-dismiss sample code. Here it is:

YMMV and I wouldn't throw it into production code just yet.

Oh, and if you find bugs (and even better, have fixes), comment here, including a link to your diff/patch/fork/etc. if you have one.
Jose Manuel Arenas García's profile photoSteffen Döring's profile photoKrishna Meena's profile photoVaibhav Adhyapak's profile photo
Thank you for sharing Roman! this is going to be a great extension to the already familiar pattern from notifications & task manager. 
+Roman Nurik - do you think this pattern could also apply to a 'mark as read' action? For example, Google+ notifications are never really deleted, but just go from an unread (new) to read (old) state. Seems much easier than opening each one.
+Ian Lake maybe as 'archive' ... the item should definitely disappear from the list, so you'd probably only want to use this if the list represents only unread items.
There's an iOS app that uses this gesture to mark items as read. What I've heard it works really well in that one. Can't remember the name just now.
Why is this a gist?  This should be a library on github~!
you can do it with simple jquery ui
Doesn't K9 Mail support swipe to mark es read? What is the difference? 
+Ian Lake I occasionally find myself trying to swipe to mark a message as read (I already read the message notification and swiped that away). It would be convenient, but as +Roman Nurik pointed out, it would be tricky to implement while maintaining consistency with the "flick off the screen" feel. The bounce Reeder uses seems to confuse the experience.

What do you think of simply swiping the unread "color" off the screen?  For example, unread messages in the ICS messaging app have a white background. Could one swipe this white rectangle with the same slide and fade effects used for notifications? 
Cool. Presents an interesting choice between swiping between pages when designing
Rob G
Look and feel nice. I'm still trying to see where could confirmation come into play and not disrupt the whole UX too much. I wouldn't want user to accidentally deleting an email or note with no way to bring it back.
The Android way is "swipe to remove from the list". I don't think that "swipe to keep in the list but change state" would feel natural to Android users.
Rob G
True, but at the moment it would only be good for the list of notifications or item that can repopulate by itself. Which, I think would be a waste since this would be really useful for list-heavy application.
There seems to be an update view bug with this when used with Jelly Bean, works fine under ICS. +Roman Nurik and +Jake Wharton is that anything you have seen? On Jelly Bean calling listAdapter.notifyDataSetChanged() in onListItemClick when having set the OnTouchListener to an instance of SwipeDismissListViewTouchListener does not update that clicked view (does not call getView() for that item). Works fine under ICS. Something changed (or regression/fix!?) in JB?

Update: Have only tested it with +Jake Wharton's backport.

Complete code to reproduce, not the best place to attach code, but anyway:

public class MainActivity extends ListActivity {
    ArrayAdapter<String> listAdapter;

    public void onCreate(Bundle savedInstanceState) {
        listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new ArrayList<String>(Arrays.asList(
                "Item 1", "Item 2", "Item 3"))) {
            public View getView(int position, View convertView, ViewGroup parent) {
                // not called for the clicked item on Jelly Bean
                Log.i("ListTest", "pos=" + position + ", convertView=" + convertView);
                return super.getView(position, convertView, parent);
        ListView listView = getListView();
        SwipeDismissListViewTouchListener touchListener = new SwipeDismissListViewTouchListener(listView,
                new SwipeDismissListViewTouchListener.OnDismissCallback() {
                    public void onDismiss(ListView listView, int[] reverseSortedPositions) {
                        for (int position : reverseSortedPositions) {
        listView.setOnTouchListener(touchListener); // comment out this and it works

    public void onListItemClick(ListView l, View v, int position, long id) {
implemented it inside ViewPager, dismiss only one direction opposite of the ViewPager direction. Works great on ICS but 2.3 and lower does not work (Its worknig when its not in ViewPager), touch get canceled event.

Any Idea someone?
Thx +Roman Nurik and +Jake Wharton for this share.
A little remark after some tests. Why put a max Velocity in the swipe gesture? I'm able to do fast swipe and so do not remove the item.
Second point, for me the min velocity used is too small. I'm able to make a swipe gesture instead of a click.
What do you think about that ?
Yes, I have the same problem. I am trying to select an item clicking it and accidentally deleted it...
+Roman Nurik what do you think about using STD on a tablet layout? The listview goes on the left column and the detail fragment on the right. It's not very intuitive, better to put an icon on the action bar when the item is selected?
it very nice! Thanks man! i think it will be good if have undorbar.
any idea if this would work with CursorAdapters??
Most anticipated for iPhone lover shifted to android and now want their android app should look like Android. BTW you have done great work and continue doing this.
thanks +Roman Nurik ! but for a listview whose rows have different height, after a row was dismissed, the height of that row next to it got the same height as the dismissed one. That's not what I want.

My solution:

replace this code:
lp.height = originalHeight;
( located at SwipeDismissListViewTouchListener#performDismiss())

 lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
awesome mate.. but i am confused because i want to implement swipe to dismiss in recyclerview. any idea?
Any Ideas how to implement it with an RecyclerView?
so what the easy way to implement it via recycle view or old way , is there any one can send me a hangouts text , so it could help me  understand the trick of this listview.
+Vasya Drobushkov Thanks for implementation. I tried it and it works. However it doesn't seem to work properly with changing row heights even with setHasFixedSize(false).
I was thinking if there's a way to implement only the swipe on the listener and do the dismiss with mRecyclerAdapter.notifyItemRemoved()

Could that work?
+Philippe Wiltgen could you provide some example, which replicates issue you mentioned. I didn't catch. You can post this as issue to github project
+Vasya Drobushkov Sure. It happens when the rows in the adapter have different heights depending on the content. For example the first row has 200dp while the next rows have 300dp. When I dismiss the first row, the viewholder will "cut" some of the following 300dp rows by 100dp. This shouldn't happen.
Maybe I'm just missing something obvious. If not I'll post it as an issue to github.
I can swipe the row left and write but I miss the implementation of the hiding views. my wise is to have two hiding views one recycle icon and the other OK icon.can any one please can show me just where i need to put those views .really a appreciated if someone could send me a hangouts text and just show me where i combine those 2 hiding views.
+Roman Nurik is RecyclerView going to improve its handling of gestures ? 
It allows to define an OnItemTouchListener and an ItemAnimator. In theory, it sounds perfect in order to cleanly implement something like SwipeToDismiss with a RecyclerView.  
However, sadly, in practice it falls flat on its face :  
-since onItemRangeRemoved checks assertNotInLayoutOrScroll each time you remove items, it crashes almost every time you try to dismiss multiple rows consecutively.  
-The animator also stops in the middle of its work with consecutive dismisses, so when it does not crashes, it tends to simply stop in the middle of an animation, leaving a gap between rows.  

I realize that I can easily port your SwipeToDismissListView code to RecyclerView (like Vasya did), but we are back to having to implement each of the cells movements ourselves, which is not really ideal and it seems to me that RecyclerView intended to solve that.
+Vasya Drobushkov Using the recylerview version do you have any idea how to make this work with a background selector drawable on the item view? It doesn't seem to pickup the selected/activated state from the onTouch/SwipeDismiss listener and the onItemTouch listeners. Setting the clickable attribute works but breaks the swipe dismiss. 
+Roman Nurik 
This may be an ignorant question, as I am somewhat new to Android dev:

Is there an obvious reason why the SwipeDismissTouchListener would not work on a ViewGroup? I.e. the item being swiped is a LinearLayout (horizontal). Later, the view I desire to dismiss could be more complex, but still be housed in a ViewGroup.

I am seeing the ACTION_DOWN take place, but ACTION_UP in the Listener never happens. I'm assuming the child views are swallowing the event, but I'm not sure. I'm inflating a linear layout from XML and adding an arbitrary number of these views based on user interaction.

After further searching, I discovered this:
I believe this means my assumption about the child views consuming the event is correct. In any case, it works now.

Problem solved! 

Roman, thank you for this excellent code. It was very easy to use.
Hi, Roman Nurik, I am new to Android development. Do you have any tutorial or a video tutorial on your java code about the SwipeToDismissListView? I really like your code. I appreciate if you can suibmit any suggestion. Thanks in advance.
Hi Roman, great library!
Can I also get swipe direction? I want to take different actions on left and right swipe. (Calling different APIs)
Also is it possible to set different background for the item when it is being swiped left or right? (Like inbox app)
Hi Roman,
am getting problem with swipeToDismiss.
when i  set onclicklistner on list-item of listview in custom adaptor,swipe is not working looking for solution ...thanks in advance.
How to implement swipe to dismiss for viewpager like in facebook android app if we swipe down or top the image is dismissed. 
Hi Can we add the background gradient while swiping the listview item ?
+Rohit Arya Plz let me know if you have find the solution of background for the item when it is being swiped left or right..

Add a comment...