Problem with onclicklistener for LinearLayout

To group the icon and text, I grouped them in linear mode and implemented a listener for the linear layout.

<LinearLayout
        android:id="@+id/ll0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="fill_horizontal"
        android:orientation="vertical" >
        <ImageButton
            android:id="@+id/imageButton0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:src="@drawable/start" />
        <TextView
            android:id="@+id/textView0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Start"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    </LinearLayout>

I implemented the listener as follows: -

l0 = (LinearLayout)findViewById(R.id.ll0);
l0.setOnClickListener(new View.OnClickListener() 
    {
        public void onClick(View v) 
        {
            //Some Code
        }
    });

The problem I am facing is that I click on the icon, the listener does not seem to respond. The listener worked when I press the space bar between the text image and the icon. I would like the whole part to be clickable, and not at any particular point.

+5
source share
1 answer

I think it ImageButtonis a clickable view and captures a click, preventing LinearLayout from receiving a click event. Try adding android:clickable="false"to the XML defining ImageButton.

- . . , LinearLayout, ImageView TextView. android:drawableTop="@drawable/start" XML, TextView, LinearLayout ImageButton. TextView.

+6

All Articles