android - Why does attaching touch listeners on an inflated layout not register touch events? -


so i've run across funky behavior while developing android app , curious why happens. when following no touch events registered:

minflatedlayout = getlayoutinflater().inflate(r.layout.my_layout, null, false); minflatedlayout.setontouchlistener(new ontouchlistener() {     public boolean ontouch(view v, motionevent event) {         log.e(tag, "hello world");         return false;     } }); 

however, when following, touch events registered:

minflatedlayout = getlayoutinflater().inflate(r.layout.my_layout, null, false); minflatedlayout.findviewbyid(r.id.child_view)     .setontouchlistener(new ontouchlistener() {         public boolean ontouch(view v, motionevent event) {             log.e(tag, "hello world");             return false;         } }); 

note: above code psuedocode-ish rewriting of actual app simplicity's sake. feel free ignore cause compile time error.

my question is, why happen? willing guess there simple going on here i'm missing, i'm little baffled thing is.

edit: layout file i'm using. it's worth, view being displayed empty view of listview.

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:orientation="vertical" >  <include     android:layout_width="match_parent"     android:layout_height="wrap_content"     layout="@layout/header_view" />  <linearlayout     android:id="@+id/child_view"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:clickable="true"     android:paddingright="?basegapsize"     android:paddingleft="?basegapsize"     android:orientation="vertical" >       <customframelayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:background="@drawable/selector_white_rounded_rect_inactive"         android:paddingbottom="?basegapsize"         android:paddingtop="?basegapsize" >          <textview             android:layout_width="match_parent"             android:layout_height="match_parent"             android:gravity="center"             android:textappearance="@style/standardlighttext" />     </customframelayout>      <customrelativelayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:background="@drawable/selector_white_rounded_rect_inactive" >          <imageview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_centerinparent="true"             android:contentdescription="@string/take_a_photo"             android:paddingbottom="?basegapsize"             android:paddingtop="?basegapsize"             android:src="@drawable/camera_with_plus" />     </customrelativelayout> </linearlayout> 

your layout may not not exposed - whole screen may occupied child view layout behind never accessible touch.. or might have

android:clickable="true" //in childview 

or

child_view.setclickable(true); 

is causing layout, not fire touch event. try removing this.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -