android ListView 不会突出显示选定的行

标签 android android-listview

在我的应用程序中,我从服务器检索用户的播放列表,并感觉到带有数据的 ListView。问题是,ListView 不会突出显示单击的行。为了防止愤怒的评论告诉我我不使用搜索,我尝试了以下方法:

  • 将我行中的按钮设置为不可聚焦
  • 通过代码和 XML(不同时)设置 listSelector
  • 尝试更改 OnItemClickListener 中传递的 View 的背景
  • 使用带有 bot true 和 false 参数的 setItemsCanFocus()
  • 将状态为“选中”和“按下”的 XML 可绘制对象设置为行布局根

检测到点击是因为我使用 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或者这个 question了解用法

关于android ListView 不会突出显示选定的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15278445/

相关文章:

android - 如何在 PageView 中设置不同大小的页面?

Android - 错误 : Unknown option '--no-crunch'

android - 长按从ListView中删除项目

android - 视频关闭手机电源问题

android - 改变方向时 fragment 膨胀错误

java - 无法对非静态字段进行静态引用...但我没有进行静态引用

java - 在 ListActivity 中使用 LongClickListener

java - ListView Adapter 如何跳过数据

android - 哪个选项卡更好?

android - 固定且始终可见的页脚位于 ListFragment 下方