How to display a button on long press of a list item

Issue

I need to display a delete button on long press of a list item..

I’ve got the code for long press.. but don’t know how to code for displaying a button inside this long press…

Solution

Finally got the answer…

.xml file

<ImageButton
        android:id="@+id/imgdelete"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/delete" 
        android:visibility="invisible"/>

.java file

      lv.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

            arg1.findViewById(R.id.imgdelete).setVisibility(View.VISIBLE);
            return false;
        }
    });
}

Answered By – Deepzz

Answer Checked By – Willingham (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.