Note that there are some explanatory texts on larger screens.

plurals
  1. POonClick not triggered on LinearLayout with child
    text
    copied!<p>I've got a custom LinearLayout with a smaller TextView child. I'd like to be able to click the area not covered by the TextView, so I set clickable=true and an onclicklistener to the LinearLayout, but onClick is not triggered. If I set the onclick listener on the TextView it works as expected...</p> <p>Anybody can help?</p> <p><b>ar_item.xml</b></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ar_item" android:layout_width="202dp" android:layout_height="62dp" android:background="@drawable/bg_item_ar" android:clickable="true"&gt; &lt;TextView android:id="@+id/ar_item_txt" android:layout_width="164dp" android:layout_height="fill_parent" android:paddingBottom="8dp" android:paddingLeft="8dp" android:paddingTop="8dp" android:paddingRight="6dp" android:gravity="center" android:background="#50000000" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><b>My custom LinearLayout</b></p> <pre><code>public class ARView extends LinearLayout { public ARView(final Context context, String name, String id) { super(context); getLayoutInflater().inflate(R.layout.ar_item, this ,true); LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.ar_item, null); TextView textView = (TextView) findViewById(R.id.ar_item_txt); textView.setText(name); setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Toast t = Toast.makeText(context, "hey!", Toast.LENGTH_SHORT); t.show(); } }); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload