Swipe listview android example

I can see the many apps with the swipe listview like Gmail, Facebook, etc. Used to perform some quick operations with the listview item.


Related Post

Listview item animation in android

Edittext in listview android example

Customize listview android


Steps to implement swipe listview

1. Create empty android project.

2. Download and Import swipe listview lib(Read More).

3. Insert swipe listview in XML.

activity_main

<com.fortysevendeg.swipelistview.SwipeListView
        android:id="@+id/example_swipe_lv_list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:listSelector="#00000000"
        swipe:swipeBackView="@+id/back"
        swipe:swipeCloseAllItemsWhenMoveList="true"
        swipe:swipeDrawableChecked="@drawable/choice_selected"
        swipe:swipeDrawableUnchecked="@drawable/choice_unselected"
        swipe:swipeFrontView="@+id/front"
 
        swipe:swipeMode="both" />

4. Setup swipe listview in MainActivity.java

swipelistview = (SwipeListView)findViewById(R.id.example_swipe_lv_list);
//setting  swipelistview as your requirement 
swipelistview.setSwipeMode(SwipeListView.SWIPE_MODE_LEFT); // there are five swiping modes
swipelistview.setSwipeActionLeft(SwipeListView.SWIPE_ACTION_REVEAL); //there are four swipe actions 
swipelistview.setOffsetLeft(convertDpToPixel(100f)); // left side offset
swipelistview.setAnimationTime(500); // Animation time
swipelistview.setSwipeOpenOnLongPress(false); // enable or disable SwipeOpenOnLongPress

5.Setup listener for the adapter buttons

ItemModel itemdata = data.get(position);
        holder.itemName.setText(itemdata.getTitle());
    
        holder.btnDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(context, "DELETE button clicked",Toast.LENGTH_SHORT).show();
}
});
      
 holder.btnEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(context, "EDIT button clicked",Toast.LENGTH_SHORT).show();
}
});
 holder.btnView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(context, "VIEW button clicked",Toast.LENGTH_SHORT).show();
}
});

Screenshots

Swipelistview example
Swipelistview example
Download

4 thoughts on - Swipe listview android example

Leave a Reply

Your email address will not be published. Required fields are marked *