简体   繁体   English

Android使用multipleChoice保存列表视图的状态

[英]Android save state of listview with multipleChoice

I have a listview that contains some values with the multipleChoice enabled in my xml file. 我有一个列表视图,其中包含一些值,并且在xml文件中启用了multiChoice。 I want to be able to save what has been checked by the user when the app is exited, then re-check what they have selected upon opening again. 我希望能够保存退出应用程序时用户检查的内容,然后在再次打开时重新检查他们选择的内容。 My code works for a radio group, but I can't seem to get it to work for this. 我的代码适用于某个广播组织,但是我似乎无法使其正常工作。

EDIT: Got this working by using some for loop trickery at the end. 编辑:最后通过使用一些for循环技巧获得了这项工作。

您可以使用SharedPreferences保留您的选择。

as @BGS wrote, SharedPreference would solve your problem. 正如@BGS所写,SharedPreference将解决您的问题。 Check out this post: MultiChoice Preference Widget for Android . 看看这篇文章: Android的MultiChoice Preference Widget

Here the values of the checkboxes are stored in a [special-separator]-separated string, and passed to the caller as a String array containing the selected values. 此处,复选框的值存储在[特殊分隔符]分隔的字符串中,并作为包含所选值的String数组传递给调用方。

I'm using this approach, and it works great so far. 我正在使用这种方法,到目前为止效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM