Android - How to save the state of a CheckBox

前端 未结 3 1414
萌比男神i
萌比男神i 2021-01-01 05:53

I have an application with checkboxes, How can i save them?

My layout is:




        
3条回答
  •  无人及你
    2021-01-01 06:32

    If you want to save simple data across sessions take a look at the documentation here: http://developer.android.com/guide/topics/data/data-storage.html specifically the shared preferences boolean storage would do the trick.

    On resume you should get the values from the shared prefs and set the checkboxes using them. On pause you should get the values from the check boxes and put them into the shared prefs.

    I also ran into this http://developer.android.com/reference/android/preference/CheckBoxPreference.html when looking at the HeloViews tutorial.

    Just some reading around, might get round to giving you some code examples if I have time later. Hope this helps.

提交回复
热议问题