編輯:關於Android編程
/**
* 偏好參數存儲工具類
*/
public class SharedPrefsUtil {
/** 數據存儲的XML名稱 **/
public final static String NAME = "QY";
/**
* 存儲數據(Long)
*/
public static void putLongValue(Context context, String key, long value) {
context.getSharedPreferences(NAME, Context.MODE_PRIVATE).edit().putLong(key, value).commit();
}
/**
* 存儲數據(Int)
*/
public static void putIntValue(Context context, String key, int value) {
context.getSharedPreferences(NAME, Context.MODE_PRIVATE).edit().putInt(key, value).commit();
}
/**
* 存儲數據(String)
*/
public static void putStringValue(Context context, String key, String value) {
context.getSharedPreferences(NAME, Context.MODE_PRIVATE).edit().putString(key, value).commit();
}
/**
* 存儲數據(boolean)
*/
public static void putBooleanValue(Context context, String key,
boolean value) {
context.getSharedPreferences(NAME, Context.MODE_PRIVATE).edit().putBoolean(key, value).commit();
}
/**
* 取出數據(Long)
*/
public static long getLongValue(Context context, String key, long defValue) {
return context.getSharedPreferences(NAME,Context.MODE_PRIVATE).getLong(key, defValue);
}
/**
* 取出數據(int)
*/
public static int getIntValue(Context context, String key, int defValue) {
return context.getSharedPreferences(NAME,Context.MODE_PRIVATE).getInt(key, defValue);
}
/**
* 取出數據(boolean)
*/
public static boolean getBooleanValue(Context context, String key,
boolean defValue) {
return context.getSharedPreferences(NAME,Context.MODE_PRIVATE).getBoolean(key, defValue);
}
/**
* 取出數據(String)
*/
public static String getStringValue(Context context, String key,
String defValue) {
return context.getSharedPreferences(NAME,Context.MODE_PRIVATE).getString(key, defValue);
}
/**
* 清空所有數據
*/
public static void clear(Context context) {
context.getSharedPreferences(NAME, Context.MODE_PRIVATE).edit().clear().commit();
}
/**
* 移除指定數據
*/
public static void remove(Context context, String key) {
context.getSharedPreferences(NAME, Context.MODE_PRIVATE).edit().remove(key).commit();
}
}
Android drawable文件夾的使用
開學到現在一直都在學著去搞明白一個簡單的游戲。寫完代碼之後,發現主界面顯示的某些圖片比正常的大了許多。本來以為是代碼寫錯了,反反復復,來來回回的檢查代碼,真心沒有錯誤。。
Android控件系列之RadioButton與RadioGroup使用方法
學習目的: 1、掌握在Android中如何建立RadioGroup和RadioButton 2、掌握RadioGroup的常用屬性 3、理解RadioButton和Che
Android自定義View實現仿GitHub的提交活躍表格
說明本文可能需要一些基礎知識點,如Canvas,Paint,Path,Rect等類的基本使用,建議不熟悉的同學可以學習GcsSloop安卓自定義View教程目錄,會幫助很
Android中在GridView網格視圖上實現item拖拽交換的方法
GridView基礎新建一個HelloGridView的工程修改main.xml代碼如下:<?xml version=1.0 encoding=utf-8&