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
I faced the same problem, and all the XML Attributes didn't work. I am not sure if this happens because i programmatically inflate and add the views, but this is how i worked around the problem.
I have a Class which extends LinearLayout, with a TextView and an ImageView. After inflating the layout and getting the views, I assigned the child views a OnClickListener, when pressed, executes the LineaLayout's onClickListner.
public class MyView extends LinearLayout {
private OnClickListener clickListener;
ImageView imageView;
TextView textView;
@Override
public void setOnClickListener(@Nullable OnClickListener l) {
super.setOnClickListener(l);
clickListener = l;
}
void afterViews() {
imageView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
clickListener.onClick(MyView.this);
return false;
}
});
textView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
clickListener.onClick(MyView.this);
return false;
}
});
}
I also tried overriding OnTouchListener, but then my child views didn't have the ripple effect, which I needed.