More and more Android apps seem to use a swipe-to-reveal or swipe-for-action UX pattern with ListViews. This is a nice way to give (power) users fast access to certain actions. One of the downsides is that these swipe gestures are often hard to discover.
If you want to use this technique, have a look at 47 degree’s android-swipelistview library.
I ran into a small issue when trying it out. When I was building my project, I got the following error:
- error: Attribute "***" has already been defined
In my case this was caused by ActionBarSherlock using the same library as the android-swipelistview project. Adding an exclusion to my Gradle build script solved this.
- compile ('com.fortysevendeg.swipelistview:swipelistview:1.0-SNAPSHOT@aar') {
- transitive = true
- exclude group: "com.android.support", module: "appcompat-v7"
- }
Usage in combination with SwipeRefreshLayout
If you want this swipe library in combination with the new SwipeRefreshLayout class, there is a little more work you need to do. To facilitate this, I have forked the original project and added the functionality as suggested by Keith Thompson in the issue he opened on the project site.
I ran into another issue where both the swipe-to-reveal as the pull-to-refresh actions were performed. This would happen when the ListView was at the top, the user would swipe horizontally and then pulled down. This has been fixed in my fork too.
An example of how to hook up this functionality can be found in Keith’s fork of the android-swipelistview project. The key classes to look at are “CustomSwipeRefreshLayout” in the sample project and “RefreshSwipeListView” in the library.
Other issues
The original android-swipelistview project has some other issues too:
- When ListView items are clickable, the item would no longer be clickable after swiping once.
- Another problem with clickable items is that sometimes they would stay in the pressed state.
The fixes for these issues have been committed to my fork of android-swipelistview too.