Android Preferencescreen using notes

Source: Internet
Author: User


Preference.xml

<?xml version= "1.0" encoding= "Utf-8"? ><preferencescreen xmlns:android= "http://schemas.android.com/apk/ Res/android "    >    <preference android:title=" basic information "        android:layout=" @layout/text_view "></ preference> <!--own definition layout-->    <checkboxpreference android:key= "checkbox"        android:title= "gender"        android:summary= "male, female"/>    <ringtonepreference android:key= "ringtone" android:title= "ringtone        Preference "        android:showdefault=" true "        android:showsilent=" true "        android:summary=" Pick a tone, any Tone "/> <listpreference android:summary=" Select a list "    android:title=" Type "    android:entries=" @ Array/my_array "<!--string-array-->    android:entryvalues=" @array/my_array "    android:key=" list "/ ><edittextpreference android:key= "edit"    android:dialogtitle= "Nihao"    android:title= "name"    / ></PreferenceScreen>

**activity.java

Package Com.lin.share;import Android.content.sharedpreferences;import Android.os.bundle;import Android.preference.edittextpreference;import Android.preference.listpreference;import Android.preference.preference;import Android.preference.preference.onpreferencechangelistener;import Android.preference.preferenceactivity;import Android.preference.preferencemanager;import Android.view.View; public class Testpreferenctscreenactivity extends Preferenceactivity {/** Called when the activity is first created. *    /Listpreference list;    Sharedpreferences prefs;        Edittextpreference edittextpreference;        @Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);       Addpreferencesfromresource (r.xml.preference);        Prefs=preferencemanager.getdefaultsharedpreferences (this);        List= (listpreference) findpreference ("list");        Edittextpreference= (edittextpreference) findpreference ("edit"); Edittextpreference.setsummary (prEfs.getstring ("edit", "Default"); Edittextpreference.setonpreferencechangelistener (New Onpreferencechangelistener () {@Overridepublic Boolean Onpreferencechange (Preference Preference, Object newvalue) {//TODO auto-generated method Stubedittextpreference.setsummary (Newvalue.tostring ()); Edittextpreference.setdefaultvalue (NewValue);        Edittextpreference.settext (Newvalue.tostring ()); return false;}}); List.setonpreferencechangelistener (New Onpreferencechangelistener () {@Overridepublic Boolean onpreferencechange ( Preference Preference, Object newvalue) {System.out.println ("change" +newvalue); List.setsummary (Newvalue.tostring ()    ); List.setvalue (newvalue.tostring ()); return false;}); }}


Android Preferencescreen using notes

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.