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; @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() { @Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
// TODO Auto-generated method stub
editTextPreference.setSummary(newValue.toString());
editTextPreference.setDefaultValue(newValue);
editTextPreference.setText(newValue.toString());
return false;
}
});
list.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
System.out.println("change"+newValue);
list.setSummary(newValue.toString());
list.setValue(newValue.toString());
return false;
}
});
} }

android PreferenceScreen使用笔记的更多相关文章

  1. Android自动化学习笔记:编写MonkeyRunner脚本的几种方式

    ---------------------------------------------------------------------------------------------------- ...

  2. Android自动化学习笔记之MonkeyRunner:官方介绍和简单实例

    ---------------------------------------------------------------------------------------------------- ...

  3. android开发学习笔记000

    使用书籍:<疯狂android讲义>——李刚著,2011年7月出版 虽然现在已2014,可我挑来跳去,还是以这本书开始我的android之旅吧. “疯狂源自梦想,技术成就辉煌.” 让我这个 ...

  4. Android动画学习笔记-Android Animation

    Android动画学习笔记-Android Animation   3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中 ...

  5. Android 数字签名学习笔记

    Android 数字签名学习笔记 在Android系统中,所有安装到系统的应用程序都必有一个数字证书,此数字证书用于标识应用程序的作者和在应用程序之间建立信任关系,如果一个permission的pro ...

  6. Android高级编程笔记(四)深入探讨Activity(转)

    在应用程序中至少包含一个用来处理应用程序的主UI功能的主界面屏幕.这个主界面一般由多个Fragment组成,并由一组次要Activity支持.要在屏幕之间切换,就必须要启动一个新的Activity.一 ...

  7. Android群英传笔记——第十二章:Android5.X 新特性详解,Material Design UI的新体验

    Android群英传笔记--第十二章:Android5.X 新特性详解,Material Design UI的新体验 第十一章为什么不写,因为我很早之前就已经写过了,有需要的可以去看 Android高 ...

  8. Android群英传笔记——第十章:Android性能优化

    Android群英传笔记--第十章:Android性能优化 随着Android应用增多,功能越来越复杂,布局也越来越丰富了,而这些也成为了阻碍一个应用流畅运行,因此,对复杂的功能进行性能优化是创造高质 ...

  9. Android群英传笔记——第九章:Android系统信息和安全机制

    Android群英传笔记--第九章:Android系统信息和安全机制 本书也正式的进入尾声了,在android的世界了,不同的软件,硬件信息就像一个国家的经济水平,军事水平,不同的配置参数,代表着一个 ...

随机推荐

  1. cxf webservice异步调用

    http://blog.csdn.net/changpingchen/article/details/9048347 http://www.oschina.net/question/780719_12 ...

  2. [LeetCode OJ] Reorder List—Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…

    For example,Given {1,2,3,4}, reorder it to {1,4,2,3}. /** * Definition for singly-linked list. * str ...

  3. @Index用法——javax.persistence.Index

    package com.springup.utiku.model; import java.io.Serializable; import javax.persistence.Entity; impo ...

  4. java jdbc 连接mysql 数据库

    JDBC连接MySQL 加载及注册JDBC驱动程序 Class.forName("com.mysql.jdbc.Driver"); Class.forName("com. ...

  5. python的bind函数

    # -*- coding:utf-8 -*- class Functor(object): def __init__(self, func, index=0, *args, **kwargs): se ...

  6. chrome代理服务器设置

    在百度的内网很难访问chrome的相关站点,如果安装一些chrome的插件很不方便,所以呢,研究了一下chrome浏览器的代理模式,FQ安装插件. Chrome设置代理服务器的方法大体有几种: 1. ...

  7. Android的5个进程等级(转)

    1.foreground process     正处于activity resume状态     正处于bound服务交互的状态     正处于服务在前台运行的状态(StartForeGround( ...

  8. 【HDOJ】3400 Line belt

    三分. #include <cstdio> #include <cstring> #include <cmath> typedef struct { double ...

  9. BZOJ1657: [Usaco2006 Mar]Mooo 奶牛的歌声

    1657: [Usaco2006 Mar]Mooo 奶牛的歌声 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 489  Solved: 338[Submi ...

  10. 【转】no resource found @integer/google_play_services_version whats this?

    原文网址:http://stackoverflow.com/questions/24325333/no-resource-found-integer-google-play-services-vers ...