Sign in
Home
Apps
Apps
App Center
Mobile App Center
Reviews
App Recommendations
News
News
All
Hardware
Accessories
Updates
Apps
Rumors
Tips and Tricks
Videos
Roms and Mods
Misc
Jobs
Forum
Forum
Overview
Recent posts
Forum Rules
Mods + Admins
General
Android
Developer Forum
Android OS Forums
ASUS Android Phones
Google Phones
HTC Phones
Huawei Phones
LG Phones
Motorola Phones
Samsung Phones
Sony Ericsson Phones
Other Android Devices
Android Tablets
Other Android Tablets
Miscellaneous
Wiki
Community
Developers
Developers
Infos
Advertise
Developers
Overview
Recent posts
Wiki
Community
Android Forum
»
Android Developer Forum
»
Android Developer Forum
» Checkbox Help
Checkbox Help
Reply
Shaun Norton
Checkbox Help
created on Sep 21, 2012 10:35:55 AM
I need help with saving the state of a Checkbox.
I want to select a checkbox, then close the app and when i open the app again, i want the checkbox to still be selected.
Please can somebody help with this or at least point me in the right direction.
Reply with quote
Reply
Link
±0
(0 votes)
ISA Nexus
RE: Checkbox Help
created on Dec 27, 2012 7:36:43 PM
Your save the value in the persistent preferences when clicked. And you read its value when populating from layout
SharedPreferences settings = getSharedPreferences("preferences", 0);
final CheckBox checkBox = (CheckBox)findViewById(R.id.yourCheckBox);
checkBox.setChecked(settings.getBoolean("checkBoxValue", false));
checkBox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences settings = getSharedPreferences("preferences", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("checkBoxValue", checkBox.isChecked());
editor.commit();
}
});
Reply with quote
Reply
Link
+1
(1 vote)
duc nguyen
RE: Checkbox Help
created on Jan 6, 2013 8:41:46 AM
Read more preferrence in android here
developer.android.com/reference/android/preference/package-summary.html
Reply with quote
Reply
Link
±0
(0 votes)
Talash
RE: Checkbox Help
created on Feb 4, 2013 12:37:21 PM
Shared preference is like a database to store the preferences. Go through the tutorial.
if any problem send the code.
Reply with quote
Reply
Link
±0
(0 votes)
Reply