本文实例讲述了android编程实现对话框的封装。分享给大家供大家参考,具体如下:
private static ProgressDialog mProgressDialog;
public static void showDefaultDialog(Context context,String title,String content,
String btnOKStr,String btnCancelStr,OnClickListener onClick){
showDefaultDialog(context, title, content, btnOKStr, btnCancelStr, onClick, null);
}
public static void showDefaultDialog(Context context,String title,String content,
String btnOKStr,String btnCancelStr,
OnClickListener onClick,OnCancelListener onCancel){
AlertDialog.Builder mBuilder = new AlertDialog.Builder(context);
if(title != null){
mBuilder.setTitle(title);
}
mBuilder.setMessage(content);
if(btnOKStr == null)
btnOKStr = "确定";
if(btnCancelStr == null)
btnCancelStr = "取消";
if(!btnOKStr.trim().equals(""))
mBuilder.setPositiveButton(btnOKStr, onClick);
if(!btnCancelStr.trim().equals(""))
mBuilder.setNegativeButton(btnCancelStr, onClick);
if(onCancel != null){
mBuilder.setOnCancelListener(onCancel);
}
mBuilder.show();
}
public static void showProgressDialog(Context context,String msg,boolean cancelable) {
// dismissProgressDialog();
mProgressDialog = new ProgressDialog(context);
mProgressDialog.setMessage(msg);
mProgressDialog.setCancelable(cancelable);
mProgressDialog.show();
}
public static void dismissProgressDialog(){
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
mProgressDialog = null;
}
}
希望本文所述对大家Android程序设计有所帮助。
您可能感兴趣的文章:Android 读取Properties配置文件的小例子android通过配置文件设置应用安装到SD卡上的方法AndroidManifest.xml配置文件解析Android 定时任务过程详解Android编程实现3D滑动旋转效果的方法Android开发之menu菜单Android编程之SMS读取短信并保存到SQLite的方法android编程之下拉刷新实现方法分析android编程实现系统图片剪裁的方法android编程实现图片库的封装方法Android编程中Perferences的用法实例分析