我ListView在我的布局中使用了这样的:
<ListView android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:layout_height="match_parent"
android:layout_weight="0.7"
android:layout_marginTop="5dp"
android:orientation="vertical"
android:layout_centerInParent="true"
android:divider="@color/dark_grey"
android:drawSelectorOnTop="false"
android:focusable="true"
android:layout_marginBottom="55dp"
android:cacheColorHint="#00000000"
android:listSelector="@color/light_grey"
android:dividerHeight="1px" />
Run Code Online (Sandbox Code Playgroud)
选择器工作得很好,但如何禁用选择器?
我试过了:
listView.clearChoices();
listView.setSelected();
listView.setSelector();
...
Run Code Online (Sandbox Code Playgroud)
还有一些东西,但没有任何作用.我有什么想法可以将我选择的项目恢复正常吗?不能那么复杂吧?
编辑:我需要一个程序化的解决方案!
谢谢!
有没有办法清除ListView中的选定项?
ListView的定义如下:
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minHeight="50dp"
android:id="@+id/example_list"
android:layout_weight="2"
android:choiceMode="singleChoice"/>
Run Code Online (Sandbox Code Playgroud)
并使用自定义适配器填充.
使用选择器突出显示所选项目:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<gradient
android:startColor="#3E5260"
android:endColor="#3E5260"
android:angle="270" />
</shape>
</item>
<item android:state_activated="true">
<shape>
<gradient
android:startColor="#3E5260"
android:endColor="#3E5260"
android:angle="270" />
</shape>
</item>
</selector>
Run Code Online (Sandbox Code Playgroud)
现在我真正拥有的是单个活动中的2个ListViews,当
在一个ListView中选择一个项目时,我想取消选择另一个ListView中的项目.
单击一个项时,两个ListView都会引发以下处理程序:
void DeviceList_Click(object sender, EventArgs e)
{
//easy enough to check which ListView raised the event
//but then I need to deselect the selected item in the other listview
}
Run Code Online (Sandbox Code Playgroud)
我尝试过这样的事情:
exampleList.SetItemChecked(exampleList.SelectedItemPosition, false);
Run Code Online (Sandbox Code Playgroud)
和
exampleList.SetSelection(-1);
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用.