0
我有一個AlertDialog的問題:我喜歡我的AlertDialog返回true,如果用戶點擊肯定按鈕,並返回false,如果他點擊否定按鈕。該功能必須阻止程序,直到用戶點擊一個按鈕。[Android] Alertdialog返回布爾onclick
我的代碼:
public static boolean errorMD5(Context context){
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(context.getString(R.string.error));
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setMessage(R.string.errorMD5);
builder.setPositiveButton(R.string.retry, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//The function return true
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
//The function return false
}
});
AlertDialog alert = builder.create();
alert.show();
}
不,它不起作用我不能在我的活動中調用函數在這個函數中(該函數在另一個類中) – Guillaume
您需要調用MyActivity.this.onUserDismissDialog(true)。 –
好吧,工作正常,謝謝! – Guillaume