gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:11:05 24 4
gpt4 key购买 nike

在我的应用程序中,我从服务器检索用户的播放列表,并感觉到带有数据的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com