-2

I have three button on listview row. I have to click on the left side red button to slide the row little bit left side and to open the delete button on the right side. On that button, by clicking I needed to delete the row. Can any one help me with this functionality? Here I attached the my layout image.

Here is image

abarisone
  • 3,707
  • 11
  • 35
  • 54
Pawan Thakur
  • 11
  • 1
  • 6

3 Answers3

1

Follow this:

  1. Make one delete button on the right side and set it's visibility to gone in xml file.

  2. When user clicks on the left side red button set delete button's visibility to visible.

  3. In the delete button's onClick method add your logic to delete the row.

Code:

<ImageButton
    android:id="@+id/category_delete"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="50dp"
    android:background="#fff"
    android:layout_alignParentLeft="true"
    android:layout_marginRight="5dp"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp"
    android:src="@drawable/img_delete_category" />


<EditText
    android:id="@+id/added_category_name"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:paddingTop="20dp"
    android:background="#fff"
    android:layout_alignParentRight="@+id/category_delete"
    android:textColor="#000"
    android:paddingLeft="10dp"
    android:fontFamily="Cabin-Regular"
    android:textSize="14dp"
    android:hint="category name"
    android:singleLine="true"
    android:layout_toRightOf="@+id/category_delete"
    android:layout_toEndOf="@+id/category_delete" />



<ImageButton
    android:id="@+id/category_edit"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="50dp"
    android:background="#fff"
    android:layout_toLeftOf="@+id/unlock_image"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp"
    android:src="@drawable/img_editcategory" />


<ImageButton
    android:id="@+id/unlock_image"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="50dp"
    android:layout_alignParentRight="true"
     android:layout_marginRight="5dp"
    android:layout_marginTop="5dp"
    android:background="#fff"
    android:layout_marginBottom="5dp"
    android:src="@drawable/img_unlocked" />
<Button
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:text="Delete"
    android:textColor="#fff"
    android:visibility="visible"
    android:id="@+id/delete_btn"
    android:background="#FF0000"

    />

Parsania Hardik
  • 4,593
  • 1
  • 33
  • 33
  • Ok i got your answer. How I can little animate to row left on opening that new delete button in the right side.Because there are two button also in the right side these button should not be hidden on opening the new delete button. – Pawan Thakur May 30 '16 at 06:25
  • add delete button in the xml of listview item. add delete button to the right side of those two buttons. when delete button's visibility is gone it's space will be covered by two buttons and when visibility is visible two buttons will be pushed to right automatically. Just implement it you will get idea. And put correct green sign and upvote answer to indicate the solution to your question.. :) – Parsania Hardik May 30 '16 at 06:30
  • the right hand side buttons are not get pushed to left when the delete buttons get visible – Pawan Thakur May 30 '16 at 09:04
  • use all buttons in the linearlayout which has orientation horizontal. If it still not working then share xml file – Parsania Hardik May 30 '16 at 09:59
  • I here tried but not opening the button in the right side http://paste.ubuntu.com/16832720/ – Pawan Thakur May 30 '16 at 11:15
  • on animating the list view row the delete button is came over to the other button ,which is left of the delete button – Pawan Thakur May 31 '16 at 05:29
  • set all view's layout_width = 0dp and add layout_weight=1 and then try..do this for all imagebuttons and edittexts....see updated answer – Parsania Hardik May 31 '16 at 07:18
0

Here is the nice library for it AndroidSwipeLayout

hope this will help you

Rohan Pawar
  • 1,875
  • 22
  • 40
0

This are the library for that

  1. Check out SwipeActionAdapter
  2. Check out SwipeMenuListView

Check This answer, too android listview slide left right

Community
  • 1
  • 1
Samarth Sevak
  • 521
  • 4
  • 16