android PreferenceScreen使用笔记
生活随笔
收集整理的這篇文章主要介紹了
android PreferenceScreen使用笔记
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
preference.xml
<?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"><Preference android:title="基本信息"android:layout="@layout/text_view"></Preference> <!--自己定義layout--><CheckBoxPreference android:key="checkbox"android:title="性別"android:summary="男 ,女"/><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="姓名"/></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;@Overridepublic 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;}});}}轉(zhuǎn)載于:https://www.cnblogs.com/lcchuguo/p/4038574.html
總結(jié)
以上是生活随笔為你收集整理的android PreferenceScreen使用笔记的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java编写文本编辑器_基于java实现
- 下一篇: 久违的SQL标准