##Android-CustomSwipeListView
Android-CustomSwipeListView that inherited from Listview and BaseAdapter supports for swiping item from right or left .
##Feature
1.Support the custom menu in the menu which is been shown by scrolling item to left.
2.Support delete item from the listview by scrolling item to right.
3.Support undo the event that is deleting item .
4.Support set the animation execution time that is been executed by swiping item from right or left.
5.Support set the delta which determines whether to swipe item from right or left .
6.Support set the flag which determines whether to enable to swipe item from right or left .
7.Easy to integrate to your app.
##Gradle Dependency
compile 'com.xyczero:customswipelistview:1.0.1@aar'
##Maven Dependency
<dependency>
<groupId>com.xyczero</groupId>
<artifactId>customswipelistview</artifactId>
<version>1.0.1</version>
<type>aar</type>
</dependency>
##ScreenShot
##Usage
It is very similar to the normal use of the ListView and BaseAdapter.
Firstly,you need to inherite the CustomSwipeBaseAdapter for your own adapter. The CustomSwipeListview can use it directly.
publicclassTestActivityextendsActivity {
privateCustomSwipeListViewmTestListView;
privateTestAdaptermTestAdapter;
... ...
}
publicclassTestAdapterextendsCustomSwipeBaseAdapter<TestModel> {
... ...
}Secondly, you need to implement some abstract function and interface that is in CustomSwipeListview and CustomSwipeBaseAdapter.
//Bind an existing item view to the data pointed to by position.@OverridepublicvoidbindItemView(Viewview, Contextcontext, intposition) {
TextViewtextViewTitle = (TextView) view.findViewById(R.id.test_title);
textViewTitle.setText(getAdapterData().get(position).getTestTitle());
... ...
}
//Bind an existing swipe left view to the data pointed to by position.@OverridepublicvoidbindSwipeLeftView(Viewview, finalContextcontext,finalintposition) {
ButtonbuttonFb = (Button) view.findViewById(R.id.test_fb_btn);
buttonFb.setOnClickListener(newOnClickListener() {
@OverridepublicvoidonClick(Viewv) {
Toast.makeText(context,"...",Toast.LENGTH_SHORT).show();
}
});
... ...
}
//Makes a new item view to hold the data pointed to by position.@OverridepublicViewnewItemView(Contextcontext, intposition, ViewGroupparent) {
finalViewmView = mLayout.inflate(R.layout.test_listview_item_view, parent, false);
returnmView;
}
//Makes a new swipe left view hold the data pointed to by position.@OverridepublicViewnewSwipeLeftView(Contextcontext, intposition, ViewGroupparent) {
finalViewmView = mLayout.inflate(R.layout.test_listview_swipe_view, parent, false);
returnmView;
}Then you can set some properties for what you want in the activity.
publicclassTestActivityextendsActivityimplementsRemoveItemCustomSwipeListener {
privateCustomSwipeListViewmTestListView;
privateTestAdaptermTestAdapter;
... ...
@OverrideprotectedvoidonCreate(BundlesavedInstanceState) {
... ...
//set remove item listenermTestListView.setRemoveItemCustomSwipeListener(this);
//set whether enable to swipemTestListView.setSwipeItemLeftEnable(true);
mTestListView.setSwipeItemRightEnable(true);
//set animation execution time in millisecondmTestListView.setAnimationLeftDuration(300);
mTestListView.setAnimationRightDuration(300);
//set deltaX that triggers swiping item in dipmTestListView.setSwipeItemLeftTriggerDeltaX(50);
mTestListView.setSwipeItemRightTriggerDeltaX(50);
... ...
}
@OverridepublicvoidonRemoveItemListener(intselectedPostion) {
TestModelmodel = mTestAdapter.removeItemByPosition(selectedPostion);
//set undoDialog message to showmUndoDialog.setMessage("Delete" + model.getTestTitle() + ".").showUndoDialog();
}
... ...
}If you need to undo the deleting item,you just some steps.
publicclassTestActivityextendsActivityimplementsRemoveItemCustomSwipeListener {
privateTestAdaptermTestAdapter;
privateCustomSwipeUndoDialogmUndoDialog;
... ...
@OverrideprotectedvoidonCreate(BundlesavedInstanceState) {
... ...
mTestAdapter = newTestAdapter(this, mTestModels);
//UndoDialog ConstructormUndoDialog = newCustomSwipeUndoDialog(this);
//set UndoActionListener,the listener is been implemented in CustomSwipeBaseAdapter.mUndoDialog.setUndoActionListener(mTestAdapter);
... ...
}
... ...
}For more detatls,please see the demo.Thank you.
##Limitations
1.You must ensure that add or set data to the adapter by using addAdapterData(...) and setAdapterData(...) in CustomSwipeBaseAdapter.
2.You must ensure that the height of the CustemListview is a certain value(like wrap_content is forbidden).
##Demo Download
##Todo List
1.add transition effect when swping left the item
2.push to Maven and Gradle
3.refactor the CustomSwipeBaseAdapter.class for more effective
##License
Apache 2
##Contact and Help
Please contact me if there is any problem when using the library.
Email: xyczero@sina.com
Blog: http://www.xyczero.com
Wechat: xyczero