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. 几种常见ECG数据格式及对比

    SCP.DICOM.HL7aECG.GDF格式及对比 本文档首先给出SCP.DICOM.HL7aECG.GDF四种心电信号格式的具体数据结构,然后分析其各自的特点及适用范围. 一.SCP-ECG fo ...

  2. Animator Override Controllers 学习及性能测试

    本文由博主(YinaPan)原创,转载请注明出处:http://www.cnblogs.com/YinaPan/p/Unity_AnimatorOverrideContorller.html  The ...

  3. hdu1102 Constructing Roads (简单最小生成树Prim算法)

    Problem Description There are N villages, which are numbered from 1 to N, and you should build some ...

  4. 10_RHEL安装搜狗输入法

    首先需要安装相关源 1.加入EPEL源 EPEL7几乎是必备的源: $ sudo yum install epel-release 2.添加mosquito-myrepo源 mosquito-myre ...

  5. OpenGL画图旋转

    #include<gl/glut.h>#include<gl/GL.h>#include<gl/GLU.h>#include<math.h>#inclu ...

  6. underscorejs-sortBy学习

    2.17 sortBy 2.17.1 语法 _.sortBy(list, iteratee, [context]) 2.17.2 说明 返回一个排序后的list拷贝副本. list为集合,如数组.对象 ...

  7. [HTML5 Canvas学习]使用颜色和透明度

    在canvas中使用颜色和透明度,通过context的strokeStyle和fillStyle属性设置,strokeStyle和fillStyle的值可以是任意有效的css颜色字串.可以用RGB.R ...

  8. Codeforces 556A Case of the Zeros and Ones(消除01)

    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u   Description Andr ...

  9. Scut:缓存管理

    Scut 的缓存管理看起来还是蛮复杂的.   redis 本身就有内存缓存+持久化的作用,Scut还是自己封装了一层内存缓存+Redis缓存+持久化. . 这是一个缩略版本的结构图. 1. 上半部分是 ...

  10. Spring <context:annotation-config/>

    在基于主机方式配置Spring的配置文件中,你可能会见到<context:annotation-config/>这样一条配置,他的作用是式地向 Spring 容器注册 AutowiredA ...