android - LinearLayout setOnClickListener does not work -


as beginner, trying set click event linearlayout listview's parent layout.it seems listview intercept linearlayout event.

here main layout:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:id="@+id/ll" android:clickable="true" tools:context=".mainactivity" > <listview     android:id="@+id/lv"     android:layout_width="match_parent"     android:layout_height="0dp"     android:layout_weight="1"     android:transcriptmode="alwaysscroll"     android:divider="@null"     android:listselector="@android:color/transparent"     /> </linearlayout> 

i use code , not work.

findviewbyid(r.id.ll).setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view view) {             log.d("mainactivity", "click");         }     }); 

yep, you're right, listview handles click. have 2 options.

  1. create subclass of linearlayout, listen touch events, , whenever needed intercept them.

  2. instead of linearlayout use framelayout , declare view height/width match_parent after listview, , set click listener on view.

    <framelayout>     <listview />     <view          android:layout_width="match_parent"         android:layout_height="match_parent" /> </framelayout> 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -