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.
create subclass of
linearlayout
, listen touch events, , whenever needed intercept them.instead of
linearlayout
useframelayout
, declare view height/widthmatch_parent
afterlistview
, , set click listener on view.<framelayout> <listview /> <view android:layout_width="match_parent" android:layout_height="match_parent" /> </framelayout>
Comments
Post a Comment