Android ListView 当项目可聚焦时,禁用点击
我正在使用带有自定义适配器的 ListView,它只有一个 TextView
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_item_content"
android:background="@drawable/list_item1"
android:layout_width="fill_parent" android:layout_height=""wrap_content"
/>
这是我的选择器背景:
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_enabled="false"
android:state_pressed="true"
android:drawable="@drawable/draw_list_item1" />
<item android:state_focused="true" android:state_enabled="false"
android:drawable="@drawable/draw_list_item_focused" />
<item android:state_focused="true" android:state_pressed="true"
android:drawable="@drawable/draw_list_item_selected" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/draw_list_item_selected" />
<item android:state_focused="true"
android:drawable="@drawable/draw_list_item_focused" />
<item android:drawable="@drawable/draw_list_item1"/>
</selector>
问题是当我设置 TextView
属性时: android:clickable="true"
和 android:focusable="true"
然后我看到了背景的焦点版本,但是设置这些会导致列表项不再响应点击和长按。删除这两个属性后,所有 ListItem 都会响应单击和长按。
应该做什么才能使可聚焦的背景可见并且单击响应都可以工作。
我尝试调用 getListView().setItemsCanFocus(true)
但问题仍然存在。
I am using a ListView with custom adapter it simply has one TextView
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_item_content"
android:background="@drawable/list_item1"
android:layout_width="fill_parent" android:layout_height=""wrap_content"
/>
Heres my selector background:
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_enabled="false"
android:state_pressed="true"
android:drawable="@drawable/draw_list_item1" />
<item android:state_focused="true" android:state_enabled="false"
android:drawable="@drawable/draw_list_item_focused" />
<item android:state_focused="true" android:state_pressed="true"
android:drawable="@drawable/draw_list_item_selected" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/draw_list_item_selected" />
<item android:state_focused="true"
android:drawable="@drawable/draw_list_item_focused" />
<item android:drawable="@drawable/draw_list_item1"/>
</selector>
The problem is when I am setting TextView
properties:android:clickable="true"
and android:focusable="true"
It is then I see my focused version of background, but setting these causes list items to no more respond to clicks and long clicks. When these 2 properties are removed all ListItems respond to clicks and long clicks.
What should be done which would make focusable background visible and click responds both to work.
I have tried calling getListView().setItemsCanFocus(true)
but problems still persists.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与 android:focusable 一起,在 TextView 上使用它,
使您的列表项可聚焦且可点击。
along with android:focusable, use this on TextView
Make sue your list items are focusable and clickable.