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 onclicklist
Create a variable for LinearLayout
LinearLayout layout;
layout.setOnClicknersetOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Toast t = Toast.makeText(context, "hey!", Toast.LENGTH_SHORT);
t.show();
}
});
android:duplicateParentState="true"
did not help me.
To make your layout clickable with its children you need add this option for every child:
android:clickable="false"
Then click handling will go up to parent.
Your TextView height covers the whole parent (whole layout) so you might clicking on empty space but not on the layout. Try using wrap_content for android:layout_height for your TextView. Set click listener for the layout as well.
None of the solutions above forked for me. Than i noticed that a LinkMovementMethod
set to TextView
inside my LinearLayout
. This class intercepts touch events, click events and properties of TextView
such as clickable, focusable vs..
If the views in question are TextView
s, you may need to set them as focusable="false"
so that the first click isn't used focusing on the text view.
Make Your parent LinearLayout's android:clickable="true"
Make all of the the childview's android:clickable="false"
Under Linearlayout - Remove android:inputType="" from TextView