android编程实现对话框的封装实例
程序员文章站
2023-11-30 22:12:40
本文实例讲述了android编程实现对话框的封装。分享给大家供大家参考,具体如下:
/**
* 对话框
*/
private static progress...
本文实例讲述了android编程实现对话框的封装。分享给大家供大家参考,具体如下:
/** * 对话框 */ private static progressdialog mprogressdialog; /** * 默认的对话框 * 标题、内容、两个按钮 * @param context * @param title * @param content * @param btnokstr 是空字符的话 该按钮不显示 (特别注意) * @param btncancelstr 是空字符的话 该按钮不显示 * @param onclick */ public static void showdefaultdialog(context context,string title,string content, string btnokstr,string btncancelstr,onclicklistener onclick){ showdefaultdialog(context, title, content, btnokstr, btncancelstr, onclick, null); } /** * 默认的对话框 + cancel事件 * @param context * @param title * @param content * @param btnokstr * @param btncancelstr * @param onclick * @param oncancel */ 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程序设计有所帮助。
上一篇: 网站关键词密度该如何调整