【发布时间】:2016-12-11 16:13:14
【问题描述】:
我有一个带有自定义适配器的 ListView,它使用 EditText 和 TextView 填充项目:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/et_choice_prob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberSigned"/>
<TextView
android:id="@+id/tv_choice_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/et_choice_prob"
android:layout_alignBaseline="@id/et_choice_prob"
android:layout_marginLeft="5dip"
/>
</RelativeLayout>
如果我想设置一个 OnItemClickListener 它永远不会被调用,因为 EditText 窃取了焦点。
另一个线程提到我应该将focusable 设置为false,这将删除实际编辑TextView 的能力。
我还尝试将ListView 的descendantFocusability 设置为任何可用选项,但均未成功。
适配器没有做任何花哨的事情,但我会根据要求提供源代码。其他所有操作都在另一个 ListFragment 上以相同的方式完成,并且可以正常工作。
【问题讨论】:
-
您是否尝试在视图的每个子项上添加 onclicklistener ? stackoverflow.com/a/6090713/2667946
-
是的……我已经在想出那种定制的解决方案了。但这真的让我很烦恼,为什么那个愚蠢的
OnItemClickListener没有触发 -
你找到解决办法了吗?
标签: android listview click focusable