Android:ListView选定项(onClick)在操作后保持选定状态

Android:ListView选定项(onClick)在操作后保持选定状态,android,listview,arraylist,selection,Android,Listview,Arraylist,Selection,我的ListView有问题。如果单击某个项目,该项目将高亮显示(这是确定的),另一个活动将开始编辑详细信息或删除数据集。返回到我的列表后,项目仍然处于选中状态,即使它不再可用 <img src="https://i.stack.imgur.com/7Xi1z.png"> <img src="https://i.stack.imgur.com/JaqCP.png"> <img src="https://i.stack.imgur.com/p3OAU.png">

我的ListView有问题。如果单击某个项目,该项目将高亮显示(这是确定的),另一个活动将开始编辑详细信息或删除数据集。返回到我的列表后,项目仍然处于选中状态,即使它不再可用

<img src="https://i.stack.imgur.com/7Xi1z.png">
<img src="https://i.stack.imgur.com/JaqCP.png">
<img src="https://i.stack.imgur.com/p3OAU.png">
here should be some pictures that i cannot insert unfortunately because the editor thinks it is code ...
并使用创建了一个可绘制的xml文件list_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false"
    android:state_selected="false"
    android:drawable="@color/colorListBackground" />
<item android:state_pressed="true">
    <shape>
        <gradient
            android:startColor="@color/colorListSelected"
            android:endColor="@color/colorListSelected"
            android:angle="270" />
    </shape>
</item>
<item android:state_pressed="false"
    android:state_selected="true"
    android:drawable="@color/colorListBackground" />
</selector>


因此,列表项将使用我的自定义颜色高亮显示,并且在选择后不会保持高亮显示状态。

请将其从片段xml的列表视图中删除:
android:listSelector=“@color/colorListSelected”

或使用

android:listSelector=“?attr/selectableItemBackground”


如果它不起作用,您可以使用自己的自定义样式。

使用runnable方法,并在选择后(大约200毫秒)移除远光灯这行代码的用途是什么
listView=(listView)rootView.findViewById(android.R.id.list)?ListView在布局文件中定义我的ListView。“但是我想我不需要那一行,对了。”阿塞姆·马罗斯,我应该在哪里插入runnable,如何删除突出显示?手动覆盖颜色?在您的列表检查中,您可以提供您的
ContractListFragment
的布局和代码吗?我在上面的帖子中添加了fragment\u list.xml、list.xml和我的数组适配器。请从您的fragment\u xml的列表视图中删除此内容:
android:listSelector=“@color/colorListSelected”
或使用android:listSelector=“?attr/selectableItemBackground”
instead@yvi,这对你有帮助吗?我找到了一个解决方案,并将它附加到我的问题中
android:listSelector="@drawable/list_selector"
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false"
    android:state_selected="false"
    android:drawable="@color/colorListBackground" />
<item android:state_pressed="true">
    <shape>
        <gradient
            android:startColor="@color/colorListSelected"
            android:endColor="@color/colorListSelected"
            android:angle="270" />
    </shape>
</item>
<item android:state_pressed="false"
    android:state_selected="true"
    android:drawable="@color/colorListBackground" />
</selector>