preference.xml
[html] view plaincopy?
<?xmlversion="1.0"encoding="utf-8"?>
<PreferenceScreenxmlns:android="http://schemas.android.com/apk/res/android"
>
<Preferenceandroid:title="基本信息"
android:layout="@layout/text_view"></Preference><!--自定义layout-->
<CheckBoxPreferenceandroid:key="checkbox"
android:title="性别"
android:summary="男,女"/>
<RingtonePreferenceandroid:key="ringtone"
android:title="RingtonePreference"
android:showDefault="true"
android:showSilent="true"
android:summary="Pickatone,anytone"/>
<ListPreferenceandroid:summary="selectalist"
android:title="Type"
android:entries="@array/my_array"<!--string-array-->
android:entryValues="@array/my_array"
android:key="list"/>
<EditTextPreferenceandroid:key="edit"
android:dialogTitle="nihao"
android:title="姓名"
/>
</PreferenceScreen>
**Activity.java
[java] view plaincopy?
packagecom.lin.share;
importandroid.content.SharedPreferences;
importandroid.os.Bundle;
importandroid.preference.EditTextPreference;

importandroid.preference.ListPreference;
importandroid.preference.Preference;
importandroid.preference.Preference.OnPreferenceChangeListener;
importandroid.preference.PreferenceActivity;
importandroid.preference.PreferenceManager;
importandroid.view.View;
publicclassTestPreferenctScreenActivityextendsPreferenceActivity{
/**Calledwhentheactivityisfirstcreated.*/
ListPreferencelist;
SharedPreferencesprefs;
EditTextPreferenceeditTextPreference;
@Override
publicvoidonCreate(BundlesavedInstanceState){
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(newOnPreferenceChangeListener(){
@Override
publicbooleanonPreferenceChange(Preferencepreference,ObjectnewValue){
//TODOAuto-generatedmethodstub
editTextPreference.setSummary(newValue.toString());
editTextPreference.setDefaultValue(newValue);
editTextPreference.setText(newValue.toString());
returnfalse;
}
});
list.setOnPreferenceChangeListener(newOnPreferenceChangeListener(){
@Override
publicbooleanonPreferenceChange(Preferencepreference,ObjectnewValue){
System.out.println("change"+newValue);
list.setSummary(newValue.toString());
list.setValue(newValue.toString());
returnfalse;
}
});
}
}