An encapsulated example of android programming implementation dialog box
- 2020-10-31 21:59:20
- OfStack
This article illustrates the encapsulation of android programming dialog box. To share for your reference, the details are as follows:
/**
* dialog
*/
private static ProgressDialog mProgressDialog;
/**
* The default dialog box
* Title, content, two buttons
* @param context
* @param title
* @param content
* @param btnOKStr Null characters The button is not displayed ( Pay special attention to )
* @param btnCancelStr Null characters The button is not displayed
* @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);
}
/**
* The default dialog box + cancel The event
* @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 = " determine ";
if(btnCancelStr == null)
btnCancelStr = " cancel ";
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;
}
}
I hope this article has been helpful in Android programming.