ProgressDialog 使用方法
progressDialog=new ProgressDialog(context);
progressDialog.setMessage(“正在加载”);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
progressDialog.dismiss();关闭
捕获back按键
重写onBackPressed()方法即可
强转数组为字符串
方法一:String.valueOf(char[] data) : 将 char 数组 data 转换成字符串
方法二:New String(char[] data)
处理数据库并发问题
/**
* 获取weatherDB实例
*/
public synchronized static WeatherDB getInstance(Context context){
if (weatherDB==null) {
weatherDB=new WeatherDB(context);
}
return weatherDB;
}
在主程序中调用这个代码:
WeatherDB weatherDB = WeatherDB.getInstance(this);
静态方法在程序执行比较早,在活动创建好以后再初始化这个数据库实例
防止硬编码
通过调用接口方式,代替硬编码,以防写错
public interface PlaceType {
public final static String province=”province”;
public final static String city=”city”;
public final static String county=”county”;
}
调用方法:String type = PlaceType.province
防止在多次保存在sharedpreference中填错其名值对中的名,造成一些难以察觉到的困扰
在SQLite数据库中建表语句规范
/**
* city表建表语句
*/
public static final String CREATE_CITY="create table city ("
+"id integer primary key autoincrement,"
+"city_name text,"
+"city_code text,"
+"province_id integer)";
为弹出菜单设置透明背景
Drawable transpent = new ColorDrawable(Color.TRANSPARENT);
mPopupWindow.setBackgroundDrawable(transpent);