Android偏好设置(4)设置默认值
Setting Default Values
The preferences you create probably define some important behaviors for your application, so it's necessary that you initialize the associated SharedPreferences file with default values for each Preference when the user first opens your application.
The first thing you must do is specify a default value for each Preference object in your XML file using theandroid:defaultValue attribute. The value can be any data type that is appropriate for the correspondingPreference object. For example:
<!-- default value is a boolean -->
<CheckBoxPreference
android:defaultValue="true"
... /> <!-- default value is a string -->
<ListPreference
android:defaultValue="@string/pref_syncConnectionTypes_default"
... />
Then, from the onCreate() method in your application's main activity—and in any other activity through which the user may enter your application for the first time—call setDefaultValues():
PreferenceManager.setDefaultValues(this, R.xml.advanced_preferences, false);
Calling this during onCreate() ensures that your application is properly initialized with default settings, which your application might need to read in order to determine some behaviors (such as whether to download data while on a cellular network).
This method takes three arguments:
- Your application
Context. - The resource ID for the preference XML file for which you want to set the default values.
- A boolean indicating whether the default values should be set more than once.
When
false, the system sets the default values only if this method has never been called in the past (or theKEY_HAS_SET_DEFAULT_VALUESin the default value shared preferences file is false).
As long as you set the third argument to false, you can safely call this method every time your activity starts without overriding the user's saved preferences by resetting them to the defaults. However, if you set it to true, you will override any previous values with the defaults.
Android偏好设置(4)设置默认值的更多相关文章
- 设置easyui input默认值
/*设置input 焦点*/ $(function () { //集体调用 $(".formTextBoxes input").each(function () { $(this) ...
- 二货Mysql中设置字段的默认值问题
Mysql设置字段的默认值的确很落伍 1.不支持函数 2.只支持固定常量. 经常用到的日期类型,因为不支持getdate或者now函数,所以只能设置timestamp类型 而且还必须在默认值那个地方写 ...
- mysql设置timpstamp的默认值为 '0000-00-00 00:00:00' 时报错
问题:mysql设置timpstamp的默认值为 '0000-00-00 00:00:00' 时报错: ERROR 1067 (42000): Invalid default value for 'u ...
- Odoo14 设置Binary字段默认值
1 # Odoo 中的附件也就是Binary字段都是经过特殊处理的 2 # 首先是上传的时候会进行base64编码后再上传到服务器 3 # 服务器进行压缩存放在odoo文件仓库中 4 # 每个odoo ...
- MySQL设置字段的默认值为当前系统时间
问题产生: 当我们在对某个字段进行设置时间默认值,该默认值必须是的当前记录的插入时间,那么就将当前系统时间作为该记录创建的时间. 应用场景: 1.在数据表中,要记录每条数据是什么时候创建的,应该由数据 ...
- [转]Hibernate设置时间戳的默认值和更新时间的自动更新
原文地址:http://blog.csdn.net/sushengmiyan/article/details/50360451 Generated and default property value ...
- jquery 设置select的默认值
<select id="sel" > <option value="s1" > aaaa </option> <opt ...
- Hibernate设置时间戳的默认值和更新时间的自动更新
Generated and default property values 生成的和默认的属性值 The database sometimes generates a property value, ...
- oracle数据库的一个表中,怎么设置字段的默认值
如果表已经存在,用如下方法设置默认值. alter table 表名 modify 字段名 default 默认值; 如test表中设置address字段为'浙江省',可用如下语句: alter ta ...
- mysql使用default来设置字段的默认值
mysql创建表时,我们可以使用default来设置表字段的默认值,这样当向表中插入或添加数据时,如果没有为此字段设置任何值,则使用default默认值来填充该字段的值 在使用create table ...
随机推荐
- POJ3262 Protecting the Flowers 【贪心】
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4418 Accepted: ...
- linux 中安装JDK
一般公司差点儿相同全部的server都是搭建在Linux上面的,所以这就免不了.(要是使用Java语言)要在Linux上面布一套JDK也就是Java虚拟机环境. 以下.我详细说一下安装过程,以及可能出 ...
- SQL - 创建一个学生表,要求有主键约束和非空约束
CREATE TABLE [dbo].[Student] ( [ID] [int] NOT NULL, [Name] [nchar](10) NOT NULL, [Age] [int] NOT NUL ...
- webstorm 6.0 注册码
User Name: EMBRACE License Key: ===== LICENSE BEGIN ===== 24718-12042010 00001h6wzKLpfo3gmjJ8xoTPw ...
- C# 中用DES 对称Key,IV 加密,前端crypto.js 解密
1.服务器端代码 #region ========加密======== /// <summary> /// 加密 /// </summary> /// <param na ...
- android 不同进程间的调用 AIDL 实现通讯服务
android 不同进程间的调用 AIDL 实现通讯服务 近期对aidl android 不同进程间的调用,不同运用间的调用做了一些尝试: 过程例如以下: 1:首先在要被调用的程序里写好 ...
- 学习Opencv 2.4.9 (一)---Opencv + vs2012环境配置
作者:咕唧咕唧liukun321 来自:http://blog.csdn.net/liukun321 首先获得最新的Opencv 2.4.9源代码:opencv源代码下载 一.Opencv环境变量配置 ...
- Android修改签名
#!/bin/shtmp=~/temp.apkcp "$1" "$tmp"zip -d "$tmp" META-INF/\*jarsigne ...
- ABAP Debug 技巧
小技巧,可以在Debugger的时候跳过不想执行的代码, 或者返回执行已经执行过的代码,实际开发过程中很有帮助
- iOS设备,fixed布局出问题
window.deviceId = '{{$deviceId}}'; window.iOS = navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? t ...