1

I've got a custom listView that I'm populating with this item layout. The problem is that the OnItemClickListener even handler of ListView only captures clicks on the imageView, but not on the other 2 textViews. Anyway to fix this?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/Fourdp"
    android:layout_marginLeft="@dimen/Fourdp"
    android:layout_marginRight="@dimen/Fourdp"
    android:layout_marginTop="@dimen/Fourdp"
    android:gravity="left|center"
    android:paddingBottom="5px"
    android:paddingLeft="5px"
    android:paddingTop="5px" 
    android:descendantFocusability="blocksDescendants">

    <ImageView
        android:id="@+id/color"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/Fourdp"
        android:layout_marginLeft="@dimen/Fourdp"
        android:layout_marginRight="@dimen/Fourdp"
        android:layout_marginTop="@dimen/Fourdp"/>

    <LinearLayout
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_gravity="left"
        android:layout_weight="1"
        android:longClickable="true"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/task"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#336699" />
    </LinearLayout>

</LinearLayout>

I've tried setting android:focusable="false" and android:clickable="false" to the ImageView, but still it doesn't work.

3 Answers 3

1

That's because the LinearLayout containing the TextViews has the android:longClickable="true" attribute.

It works if you remove it.

Why do you need it ? You can use the setOnLongClickListener() method of the ListView to detect long clicks on items.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to implement a onclicklistner for the items in your adapter (where you inflate the row view)

public View getView(int position, View convertView, ViewGroup parent) 
        {

             View v = convertView;
             if (v == null) 
             {
                 LayoutInflater vi = (LayoutInflater)InAppPurchaseActivity.this.getParent().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                 v = vi.inflate(R.layout.list_item_product, null);
             }

            // add your view with onclicklistner here


             return v;
        }

Comments

0

//add this line in your both textview android:duplicateParentState="true" this will work.

<LinearLayout
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_gravity="left"
        android:layout_weight="1"
        android:longClickable="true"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/task"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:duplicateParentState="true"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:duplicateParentState="true"
            android:textColor="#336699" />
    </LinearLayout>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.