【发布时间】:2010-12-31 09:28:03
【问题描述】:
我正在使用带有自定义适配器的 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),但问题仍然存在。
【问题讨论】:
标签: android listview background click focusable