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. dota监测

    漫漫长假一个人无聊得很,整日DOTA,打的腰酸背痛腿抽筋的.就想着写一个脚本记录自己每天打游戏的时间,于是就产生了下面的这个东西... 运行环境:win7 32位. python版本:3.4.1 由于 ...

  2. 初涉JavaScript模式 (13) : 代码复用 【上】

    引子 博客断了一段时间,不是不写,一是没时间,二是觉得自己沉淀不够,经过一段时间的学习和实战,今天来总结下一个老生常谈的东西: 代码复用. 为何复用 JS门槛低,故很多人以为写几个特效就会JS,其实真 ...

  3. extjs combobox 设置下拉时显示滚动条 设置显示条数

    extjs在点击下拉时如果没有限制它的高度,那么它的默认最大高度是300,显示的时候就会显示300的高度,知道选项内容超过这个高度时才会自动显示滚动条,往往在有些时候我们希望让combobox显示一个 ...

  4. php 用于绘图使用的颜色数组

    $colorArr = array(0x912CEE, 0x99ff00, 0x312520, 0x801dae, 0x25f8cb, 0xCC3333, 0x808080, 0xa29b7c, 0x ...

  5. win10 64bit 安装scrapy-1.1

    0.环境说明 win10 64bit,电脑也是64bit的处理器,电脑装有vs2010 64bit,但是为了保险起见,只试验了32位的安装,等有时间了,再试下64位的安装.如无特殊说明,一切操作都是在 ...

  6. postgres常用类型

    数值类型 名字 存储空间 描述 范围 smallint 2 字节 小范围整数 -32768 到 +32767 integer 4 字节 常用的整数 -2147483648 到 +2147483647 ...

  7. Sample rate 理解

    在Gnuradio中,我们可以看到很多模块中都有Sample rate 这个概念 然后看到一个说明 Any processing block's 'Sample Rate' parameter is ...

  8. CodeForces 474B(标记用法)

    CodeForces 474B Time Limit:1000MS Memory Limit:262144KB   64bit IO Format:%I64d & %I64u Descript ...

  9. IPv6套接字地址结构

    IPv6套接字地址结构 struct in6_addr{ unit8_t sa_addr[16]; }; #define SIN6_LEN struct sockaddr_in6{ unit8_t s ...

  10. poj 1606Jugs

    http://poj.org/problem?id=1606 #include<cstdio> #include<cstring> #define MAXN 1000000 u ...