Android - 初心者 - AlertDialog

Android - 初心者 - AlertDialog

 

這個算是很基本,只是因為很常用,

所以我包成了兩個常用方法,一種是單純的顯示,一種是選擇是與否的顯示

public class DialogUtils {
    public static AlertDialog showConfirmDialog(Context ctx,String title,String msg,String btnOkName,String btnCancelName,DialogInterface.OnClickListener okClick,DialogInterface.OnClickListener cancelClick){
        return new AlertDialog.Builder(ctx)
                .setTitle(title)
                .setMessage(msg)
                .setPositiveButton(btnOkName, okClick)
                .setNegativeButton(btnCancelName,cancelClick)
                .show();
    }

    public static AlertDialog showNoticeDialog(Context ctx,String title,String msg,String btnOkName,DialogInterface.OnClickListener okClick){
        return new AlertDialog.Builder(ctx)
                .setTitle(title)
                .setMessage(msg)
                .setPositiveButton(btnOkName, okClick)
                .show();
    }
}