代码如下 | 复制代码 |
/** * 弹出一个带确认和取消的dialog * @param context * @param title * @param msg * @param okbutton * @param ok 点击确定事件 * @param nobutton * @param no 点击取消事件 * @return */ publicstaticAlertDialog openConfirmDialog(Context context, String title, String msg, String okbutton, OnClickListener ok, String nobutton, OnClickListener no) { Builder builder =newBuilder(context); builder.setTitle(title); builder.setMessage("n"+ msg +"n"); builder.setNegativeButton(okbutton, ok); builder.setNeutralButton(nobutton, no); AlertDialog loadWaitDialog = builder.create(); loadWaitDialog.setCanceledOnTouchOutside(false); loadWaitDialog.show(); returnloadWaitDialog;
}
/** * 监听返回按钮 */ publicbooleanonKeyDown(intkeyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_BACK) {
YourTools.openConfirmDialog(this,"","是否退出?","确定", newDialogInterface.OnClickListener() {
@Override publicvoidonClick(DialogInterface dialog, intwhich) { //TODO } },"取消",newDialogInterface.OnClickListener() {
@Override publicvoidonClick(DialogInterface dialog, intwhich) {
//TODO } });
returnfalse; } |