Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android ListView不会突出显示所选行大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的应用程序中,我从服务器检索用户的播放列表,并感受带有数据的ListView.问题是,ListView没有突出显示单击的行.为了防止愤怒的评论告诉我我不使用搜索这里是我尝试过的事情:

>将我的行中的按钮设置为不可聚焦
>通过代码XML设置list@R_616_10288@ctor(不是同时)
>尝试在OnItemClickListener中更改传递的View的背景
>使用带有bot true和false参数的setItemsCanFocus()
>使用“@R_616_10288@cted”和“pressed”状态设置XML drawable到行布局根目录

自从我使用Toast测试后,检测到了点击.但我只是无法强制ListView突出显示所选行

列表显示

<ListView
    android:id="@android:id/list"
    android:list@R_616_10288@ctor="@drawable/list_@R_616_10288@cted"
    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://scheR_123_11845@as.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>

有什么建议?

解决方法

在drawables文件夹中为列表视图创建一个选择器,并将列表项背景设置为此drawable.请参阅下面的代码

@R_616_10288@cT_Button_BACkground.xml

<?xml version="1.0" encoding="utf-8"?>
<@R_616_10288@ctor xmlns:android="http://scheR_123_11845@as.android.com/apk/res/android">
    <item android:drawable="@drawable/@R_616_10288@cT_Button_@R_616_10288@cted" android:state_enabled="true" android:state_pressed="true"/>
    <item android:drawable="@drawable/@R_616_10288@cT_Button_@R_616_10288@cted" android:state_enabled="true" android:state_@R_616_10288@cted="true"/>

    <item android:drawable="@drawable/@R_616_10288@cT_Button_@R_616_10288@ctable" android:state_pressed="false"/>
    <item android:drawable="@drawable/@R_616_10288@cT_Button_@R_616_10288@ctable" android:state_@R_616_10288@cted="false"/>
 </@R_616_10288@ctor>

@R_616_10288@cT_Button_@R_616_10288@ctable.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://scheR_123_11845@as.android.com/apk/res/android" >

    <gradient
        android:angle="270"
        android:endColor="#CCCCCC"
        android:startColor="#DDDDDD"
        android:type="linear" />

    <corners android:radius="10dp" />

    <shape>
        <stroke
            android:width="1dp"
            android:color="#333333" />
    </shape>

</shape>

@R_616_10288@cT_Button_@R_616_10288@cted.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://scheR_123_11845@as.android.com/apk/res/android" >

    <gradient
        android:angle="270"
        android:endColor="#AAAAAA"
        android:startColor="#bbbbBB"
        android:type="linear" />

    <corners android:radius="10dp" />

    <shape>
        <stroke
            android:width="1dp"
            android:color="#333333" />
    </shape>

</shape>

大佬总结

以上是大佬教程为你收集整理的android ListView不会突出显示所选行全部内容,希望文章能够帮你解决android ListView不会突出显示所选行所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。