如何保持警告对话框,直到Ok点击android

时间:2014-10-16 12:42:24

标签: android alert android-alertdialog

我有一个登录屏幕,当点击登录按钮时,弹出窗口显示确定。 我的需要是弹出弹出直到Ok点击。

3 个答案:

答案 0 :(得分:1)

喜欢这个

    public static void showMessageDialogWithIntent(final Activity activity, String Message, final String intentClassName) throws ClassNotFoundException {
    Log.e(TAG, "showMessageDialogWithIntent");
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setMessage(Message).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            try {
                // do work here
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });
    builder.setCancelable(false);
    builder.create().show();
}

答案 1 :(得分:1)

这是方式:

  AlertDialog alertDialog = new AlertDialog.Builder(
                    AlertDialogActivity.this).create();

    // Setting Dialog Title
    alertDialog.setTitle("Alert Dialog");

    // Setting Dialog Message
    alertDialog.setMessage("Hello ,");

    // Setting OK Button
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
            // Write your code here to execute after dialog closed
            //Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
             alertDialog.cancel();
            }
    });

    // Showing Alert Message
    alertDialog.show();

答案 2 :(得分:0)

你可以通过使用来做到这一点 setCancelable(false)喜欢这个

AlertDialog.Builder builder = new Builder(context);
    builder.setMessage("Some Message");
    builder.setTitle("You Title");
    builder.setCancelable(false);
    builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            //I won't add finish() here
        }
    });

    builder.create().show();