Wednesday, 8 April 2015

Swipelistview in android

Swipelisview in android

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

Steps:
1.Create empty android project.

2.Import swipelistview lib.

3.Insert swipelistview in xml.




<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 swipelistview in 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();
}
});
        


Screenshot:




DOWNLOAD SAMPLE CODE



No comments: