java - Android LinearLayout, last added children stealing click for onClickListener -


setup:

i have custom linearlayout has textview , imageview inside (my attempts resolve issue commented out):

public class mytextview extends linearlayout {      private final textview textview;     private final imageview imageview;      public mytextview(context context, attributeset attrs) {         super(context, attrs);         setorientation(vertical);          textview = new textview(context);         imageview = new imageview(context);          layoutparams layoutparams = new layoutparams(layoutparams.match_parent,                 layoutparams.wrap_content);         imageview.setlayoutparams(layoutparams);         imageview.setimageresource(r.drawable.img);          /* imageview.setduplicateparentstateenabled(true);          textview.setduplicateparentstateenabled(true); */          /* imageview.setfocusable(false);         textview.setfocusable(false);         textview.settextisselectable(false); */          addview(textview);         addview(imageview);          /* this.setdescendantfocusability(focus_block_descendants);         this.setclickable(true); */      } } 

i'm including custom linearlayout in larger layout:

<?xml version="1.0" encoding="utf-8"?>  <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical" >     <my.package.mytextview         android:id="@+id/textview"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:textappearance="?android:attr/textappearancesmall" />  </linearlayout> 

i'm setting onclicklistener way:

final mytextview textview = (mytextview) view.findviewbyid(r.id.textview); textview.setonclicklistener(new view.onclicklistener() {     @override     public void onclick(view view) {         // code     } }); 

my issue:

the onclicklistener fires if tap imageview, , not textview. i'd work if tap part of linearlayout instead.

i can't understand why wouldn't work, not e.g. setdescendantfocusability set focus_block_descendants, , appreciate explanation. lot.

the problem setmovementmethod being called on textview , didn't notice.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -