android 利用SharedPreferences 存储系统数据的高级应用(枚举)
来源:互联网 发布:tushare 获取股票数据 编辑:程序博客网 时间:2024/05/09 03:45
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
public class SystemAPP {
private final String PREFERENCE_NAMR = "systemdb.xml";//目标配置文件
private SharedPreferences mySharedPreferences;
private SharedPreferences.Editor editor;
public SystemAPP(Context context) {
mySharedPreferences = context.getSharedPreferences(PREFERENCE_NAMR, Activity.MODE_PRIVATE);
editor = mySharedPreferences.edit();
}
/**
* 根据枚举名称相对应添加或者更新新数据
* @param name 枚举名称
*/
public boolean createOrUpdataName(MySystemEnum name){
editor.putString(name.toString(),name.getValue());
if(editor.commit()){
return true;
}
return false;
}
/**
* 根据枚举名称添加或者 修改对于的数据值
* @param name 名称
* @param value 目标值
*/
public boolean createOrUpdataName(MySystemEnum name,MySystemEnum value){
editor.putString(name.toString(), value.getValue());
if(editor.commit()){
return true;
}
return false;
}
/**
* 根据枚举名称得到相对应的值
* @param name 枚举名称
* @return 数据值
*/
public String getValue(MySystemEnum name){
return mySharedPreferences.getString(name.getValue(), "没有数据.");
}
/**
* 情况配置文件所有内容
*/
public boolean deleteAll(){
editor.clear();
if(editor.commit()){
return true;
}
return false;
}
/**
* 根据枚举名称来删除该数据
* @param name 枚举名称
*/
public boolean deleteName(MySystemEnum name){
editor.remove(name.toString());
if(editor.commit()){
return true;
}
return false;
}
}
package com.lyc;
/*
* 系统配置文件枚举
*/
public enum MySystemEnum {
homepage("homepage"), //首页
newProduct("newProduct"), //新品
cookRecommend("cookRecommend"), //厨师推荐
foodLevel("foodLevel"), //菜单级别
news("news"), //公告栏
video("video"), //视频
food1("food"), //菜
foodName("foodName"),
foodValue1("foodType1"),
foodValue2("foodType2");
private String value;
MySystemEnum(String value){
this.value = value;
}
public String getValue() {
return value;
}
}
package com.lyc;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class SystemDBActivity extends Activity {
/** Called when the activity is first created. */
private TextView textView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SystemAPP app = new SystemAPP(this);
app.createOrUpdataName(MySystemEnum.foodLevel);
textView = (TextView)findViewById(R.id.text_name);
textView.setText(app.getValue(MySystemEnum.foodLevel));
app.createOrUpdataName(MySystemEnum.foodLevel,MySystemEnum.foodName);
}
}
- android 利用SharedPreferences 存储系统数据的高级应用(枚举)
- Android SharedPreferences 保存数据,读取其它应用的SharedPreferences
- android 利用SharedPreferences 在不同应用之间共享数据
- Android 利用SharedPreferences存储数据
- android SharedPreferences保存应用数据
- android利用SharedPreferences进行用户数据的回显
- android 读写其他应用SharedPreferences存储的数据
- Android应用开发SharedPreferences存储数据的使用方法
- Android 中SharedPreferences跨应用读取数据的
- Android应用开发SharedPreferences存储数据的使用方法
- Android应用开发SharedPreferences存储数据的使用方法
- Android应用开发SharedPreferences存储数据的使用方法
- Android应用开发SharedPreferences存储数据的使用方法
- Android应用开发SharedPreferences存储数据的使用方法
- Android应用开发SharedPreferences存储数据的使用方法
- Android应用开发SharedPreferences存储数据的使用方法
- Android应用开发SharedPreferences存储数据的使用方法
- Android应用开发SharedPreferences存储数据的使用方法
- android之壁纸机制
- windows编程中文件操作
- java 中的Exception RuntimeException 区别
- 从摄像头获取_保存视频(CV_FOURCC可以获取的视频编码格式)
- php教程判断字符串是否大小写字母函数
- android 利用SharedPreferences 存储系统数据的高级应用(枚举)
- ffmpeg编译及使用
- CGContextRef
- 单点登录通俗说明
- live555学习笔记2-基础类
- php 编一函数计算一个字符串中有多少个字母.汉字.数字?
- DB2--远程连接数据库
- VC 注册表操作
- 图说天下