我目前正在尝试使用数据绑定将点击监听器设置到LinearLayout
视图中的.xml
布局文件上。
我已经成功地在其他视图上实现了它,比如Button
或TextView
,但因某种原因,在LinearLayout
上不起作用。
以下是我尝试的基本内容,但仍然无法使其工作:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="72dp"
android:clickable="true"
android:focusable="true"
android:onClick="@{action::linearLayoutClicked}"
android:orientation="vertical">
</LinearLayout>
其中linearLayoutClicked
是我在操作类中定义的方法:
public void linearLayoutClicked(View view) {
// specific logic
}
我也尝试了使用子视图和这些子视图设置为clickable
和focusable
都设置为false,同时将duplicateParentState
设置为true
和false
。
该操作与其他正常工作的视图上正在使用的操作完全相同。
这是一个bug还是我做错了?为什么这在LinearLayout
上不起作用,但在其他视图上没有任何问题?
android:onClick()
属性,并在您的LinearLayout上调用setOnClickListener()
,您会得到想要的结果吗? - CommonsWareLinearLayout
上可以正常工作。 - Shadow