在我的应用程序中,我从服务器检索用户的播放列表,并感受到ListView
与数据。问题是,ListView
不突出显示单击的行。为了防止愤怒的评论告诉我我不使用搜索,我尝试过以下方法:
- 将我行中的按钮设置为不可聚焦
- 通过代码和 XML 设置 listSelector(不同时)
- 试图改变过去的背景
View
in an OnItemClickListener
- 使用带有 bot true 和 false 参数的 setItemsCanFocus()
- 将状态为“已选择”和“已按下”的 XML 可绘制对象设置为行布局根
自从我使用 a 进行测试以来,检测到了点击Toast
。但我就是不能强迫ListView
突出显示所选行
ListView
<ListView
android:id="@android:id/list"
android:listSelector="@drawable/list_selected"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/etbg"
android:choiceMode="singleChoice"
android:divider="@color/div" >
</ListView>
用作列表行的布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/tvListItemArtist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="14dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Small Text"
android:layout_toRightOf="@+id/tbListPlay"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />
<TextView
android:id="@+id/tvListItemSong"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/tvListItemArtist"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/tvListItemArtist"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />
<ImageView
android:id="@+id/img_list_audio_saved"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="50dp"
android:src="@drawable/attention"
android:visibility="gone" />
<Button
android:id="@+id/tbListPlay"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="@drawable/button_play"
android:focusable="false"
android:focusableInTouchMode="false" />
</RelativeLayout>
有什么建议么?
您已经更改了 ListSelector:android:listSelector="@drawable/list_selected"
我假设您的自定义可绘制对象不是选择器,它具有不同的状态。看到这个site http://developer.android.com/guide/topics/resources/drawable-resource.html或这个question https://stackoverflow.com/q/1219312/1173391了解用法
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)