简体   繁体   English

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

[英]Android: Save state of list view using savedInstanceState

I have a standard implementation of a ListView (one which uses an Array Adapter) and one of the in-built layouts R.layout.simple_list_item_multiple_choice . 我有一个ListView的标准实现(一个使用数组适配器)和一个内置布局R.layout.simple_list_item_multiple_choice

Anyway, I was reading about Activity lifecycle and how when the screen orientation changes or if a phone call occurs, one way to restore the Activity state is using the onSaveInstanceState and onRestoreInstanceState methods. 无论如何,我正在阅读有关Activity生命周期以及如何改变屏幕方向或何时发生电话呼叫的信息,一种恢复Activity状态的方法是使用onSaveInstanceStateonRestoreInstanceState方法。

My question is, can someone help me how can I store the state of a ListView (not customised) into a bundle, this includes its entries, position and checked items 我的问题是,有人可以帮助我如何将ListView (未自定义)的状态存储到捆绑包中,其中包括其条目,位置和选中的项目

Many thanks 非常感谢

You want your data to be persistent. 您希望数据是持久的。 For that you have to use SQLite database or SharedPreferences. 为此,您必须使用SQLite数据库或SharedPreferences。 You can also use device's internal storage or external storage according to your needs. 您也可以根据需要使用设备的内部存储或外部存储。 Here is the link which will provide detailed explanation. 是将提供详细说明的链接。

onSaveInstanceState is for instances when accidentally your App's data is lost like by killing the process or when a phone call comes. onSaveInstanceState适用于偶然丢失应用程序数据(例如终止进程或打来电话)的数据的情况。 You cannot store data in onSaveInstanceState deliberately to retrieve it according to your needs. 您不能根据需要将数据故意存储在onSaveInstanceState以进行检索。

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

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