Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView's Item longClick not working with ImageView(Clickable)

I have a listView with items that contains textview and imageView (when clicking on imageView it should show fullScreen image), and when longPressing any item, then should show a popup.

All things are working fine until I try to longClick using imageView. because when I put touch on ImageView , listView's longClick method not getting called, and after pulling touch, imageView's click get called.

And I want it to be like that :

When longClicking on imageView/listItem, it should show only alert and on single click on imageView it should show fullScreen image.

Please help me with any suggestions.

like image 575
NehaK Avatar asked Jan 13 '17 09:01

NehaK


1 Answers

Finally, I've found solution for this issue :

I needed to return "true" in longClickListener. like :

lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
    @Override
    public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
        Log.d("debug", "onLongClick = " + i + "  " + view.getTag());
        return true;
    }
});

And needed to add following line in item_view.xml :

for superParent layout add line :

android:descendantFocusability="blocksDescendants"

for that imageView :

android:longClickable="true"

Example :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:descendantFocusability="blocksDescendants"
    android:gravity="center"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/text_view"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:longClickable="true"
        android:background="#ff0000" />

</LinearLayout>
like image 130
NehaK Avatar answered Oct 19 '22 19:10

NehaK