单击按钮时如何取消选择 ListView 中的项目
How to unselect items in a ListView when clicking a button
我有一个带有列表选择器的列表视图,我想知道是否可以有一个按钮来取消选择项目并让列表不选择任何项目(我只想删除突出显示栏,而不是项目).
这是我的列表视图配置:
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="386dp"
android:choiceMode="singleChoice"
android:focusable="true"
android:focusableInTouchMode="true"
android:listSelector="@android:color/darker_gray"
</ListView>
我在想类似的东西:
btn1.setOnClickListener {
listView1.listselector = false
}
提前感谢您的支持。
您必须更改 ListView 的 choiceMode 并重新分配适配器:
btn1.setOnClickListener {
listView1.choiceMode = ListView.CHOICE_MODE_NONE
listView1.adapter = adapter
}
但是如果你只是想清除选中的项目
listView1.adapter = adapter
够了
我有一个带有列表选择器的列表视图,我想知道是否可以有一个按钮来取消选择项目并让列表不选择任何项目(我只想删除突出显示栏,而不是项目).
这是我的列表视图配置:
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="386dp"
android:choiceMode="singleChoice"
android:focusable="true"
android:focusableInTouchMode="true"
android:listSelector="@android:color/darker_gray"
</ListView>
我在想类似的东西:
btn1.setOnClickListener {
listView1.listselector = false
}
提前感谢您的支持。
您必须更改 ListView 的 choiceMode 并重新分配适配器:
btn1.setOnClickListener {
listView1.choiceMode = ListView.CHOICE_MODE_NONE
listView1.adapter = adapter
}
但是如果你只是想清除选中的项目
listView1.adapter = adapter
够了