Android Learning 13 First options

Source: Internet
Author: User

1, preferences can be used to persist user settings, game highest score, etc.

2, preferences have, list preferences, check box Preferences, dialog Preferences: 3, creating preferences through XML files and code Addpreferencesfromresource (R.xml.main) 4. Get values from preferencesResources Resources = This. Getresources ();sharedpreferences spf= Preferencemanager. getdefaultsharedpreferences ( This);String option = spf.getstring (resources.getstring (r.string. Flight_sort_key),resources.getstring (r.string. Flight_sort_default_value ));              string[] Optionarray = Resources.getstringarray (r.array. filght_sort_option );5. Determine if there is a value for a preference Boolean haspreferences = Myprefs.getboolean (INITIALIZED, false);
if (haspreferences) {
LOG.V ("Preferences", "We ' ve been called before");
Read other values as desired from preferences file ...
somestring = myprefs.getstring ("somestring", "" ");
}
else {
LOG.V ("Preferences", "first time ever being called");
Set up initial values for what would end up
In the Preferences file
somestring = "some default value";
}
Later when ready-to-write out values6. Set the value of Preferences in codeEditor editor = Myprefs.edit ();
CHAPTER 13:working with Preferences and saving State 359
Editor.putboolean (INITIALIZED, true);
Editor.putstring ("somestring", somestring);
Write other values as desired
Editor.commit ();    7. Preferences can be nested, and parent-child relationships may exist. 8 General Steps A. Layout preferences in the XML file B. Create an activity to inherit from Preferenceactivity, and then pass   Addpreferencesfromresource () Create a view C. Get and set values by appropriate methods   

Android Learning 13 First options

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.