You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SwipeActionAdapter is a library that provides a simple API to create Mailbox-like action when swiping in a ListView. The idea is to make it simple enough to implement while still providing sufficient options to allow you to integrate it with the design of your application.
4
+
SwipeActionAdapter is a library that provides a simple API to create Mailbox-like action when swiping in a ListView.
5
+
The idea is to make it simple enough to implement while still providing sufficient options to allow you to
6
+
integrate it with the design of your application.
5
7
6
-
Support for Android 4.0 and up. It might work on lower API versions, but I haven't tested it and I don't intend to make any effort in that direction.
8
+
Support for Android 4.0 and up. It might work on lower API versions, but I haven't tested it and I don't intend to
9
+
make any effort in that direction.
7
10
8
11
Feel free to fork or issue pull requests on github. Issues can be reported on the github issue tracker.
9
12
@@ -16,7 +19,8 @@ Setup
16
19
17
20
*[Download the jar file](https://github.com/wdullaer/SwipeActionAdapter/releases) and add it to your project
18
21
19
-
If you would like to get the most recent code in a jar, clone the project and run ```./gradlew jar``` from the root folder. This will build a swipeactionadapter.jar in ```library/build/libs/```.
22
+
If you would like to get the most recent code in a jar, clone the project and run ```./gradlew jar``` from
23
+
the root folder. This will build a swipeactionadapter.jar in ```library/build/libs/```.
20
24
21
25
You may also add the library as an Android Library to your project. All the library files live in ```library```.
22
26
@@ -33,7 +37,11 @@ For a basic implementation, you'll need to
33
37
34
38
### Wrap the adapter of you ListView
35
39
36
-
The majority of this libraries functionality is provided through an adapter which wraps around the content ```Adapter``` of your ```ListView```. You will need to set the SwipeActionAdapter to your ListView and because we need to set some properties of the ListView, you will also need to give a reference of the ```ListView``` to the ```SwipeActionAdapter```. This is typically done in your ```Activity```'s or ```Fragments``` onCreate/onActivityCreated callbacks.
40
+
The majority of this libraries functionality is provided through an adapter which wraps around the content ```Adapter```
41
+
of your ```ListView```. You will need to set the SwipeActionAdapter to your ListView and because
42
+
we need to set some properties of the ListView, you will also need to give a reference of the ```ListView```
43
+
to the ```SwipeActionAdapter```.
44
+
This is typically done in your ```Activity```'s or ```Fragments``` onCreate/onActivityCreated callbacks.
### Create a background layout for each swipe direction
64
72
65
73
I'm just supplying an empty layout with a background for each direction.
66
-
You should have a layout for at least ```SwipeDirections.DIRECTION_NORMAL_LEFT``` and ```SwipeDirections.DIRECTION_NORMAL_RIGHT```. The other directions are optional.
74
+
You should have a layout for at least ```SwipeDirections.DIRECTION_NORMAL_LEFT``` and ```SwipeDirections.DIRECTION_NORMAL_RIGHT```.
75
+
The other directions are optional.
67
76
It is important that the background layouts have the same height as the normal row layout.
68
77
The ```onCreate``` callback from the previous section now becomes:
The final thing to do is listen to swipe gestures. This is done by implementing the ```SwipeActionListener```. This interface has two methods:
123
+
The final thing to do is listen to swipe gestures. This is done by implementing the ```SwipeActionListener```.
124
+
This interface has three methods:
115
125
*```boolean hasActions(int position)```: return true if you want this item to be swipeable
116
-
*```boolean onSwipe(int position, int direction)```: triggered when an item is swiped. Return true if you want the item to be dismissed, return false if it should stay visible. This method runs on the interface thread so perform any heavy logic in an ASyncThread
126
+
*```boolean shouldDismiss(int position, int direction)```: return true if you want the item to be dismissed,
127
+
return false if it should stay visible. This method runs on the interface thread so if you want to trigger any
128
+
heavy actions here, put them on an ```ASyncThread```
129
+
*```void onSwipe(int[] position, int[] direction)```: triggered when all animations on the swiped items have finished.
130
+
You will receive an array of all swiped items, sorted in descending order with their corresponding directions.
131
+
117
132
You should pass a reference of your ```SwipeActionListener``` to the ```SwipeActionAdapter```
118
133
119
134
Here's the final implementation of our example's ```onCreate``` method:
0 commit comments