AlertDialog显示在模拟器中但不在手机中

时间:2016-05-31 11:15:56

标签: android alertdialog

我是一个可怕的程序员,但他设法推出了一个应用程序,我的同事使用这个应用程序来减轻他们的日常工作。我现在被要求放入一个对话框。就像我一直这样,我长时间搜索互联网并且或多或少地偷了解决方案。我在尝试模拟器时实现了很大的成功。然而,当我在同事手机上更新应用程序时它没有工作 - 应用程序仍然可以正常工作,但没有显示对话框。

我的猜测是,这与设备的API级别有关。但根据我的研究,AlertDialog已经有一段时间了。我需要在带有Android 4.1.2版的手机上显示对话框。

以下是我的代码,希望这是一个简单的错误,或者有人可以帮我解决另一个问题。我没有收到任何错误。

非常感谢提前!

        DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch (which){
                case DialogInterface.BUTTON_POSITIVE:
                    showUrl = "http://randomurl.php";
                    break;

                case DialogInterface.BUTTON_NEGATIVE:
                    //No button clicked
                    break;
            }
        }
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(Main2Activity.this);
    builder.setMessage("Yes or No?").setPositiveButton("yes", dialogClickListener)
            .setNegativeButton("no", dialogClickListener).show();

1 个答案:

答案 0 :(得分:0)

AlertDialog.Builder alertDialog = new AlertDialog.Builder(RecordActivity.this);

    // Setting Dialog Message
    alertDialog.setMessage("alert_message"));

    // Setting Positive "Yes" Button
    alertDialog.setPositiveButton("Click Here", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

            Intent i = new Intent(RecordActivity.this, PurchaseActivity.class);
            startActivityForResult(i, RESULT_ACTIVITY_PURCHASE);
            dialog.dismiss();
        }
    });

    // Setting Negative "NO" Button
    alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

            dialog.dismiss();

        }
    });

    // Showing Alert Message
    alertDialog.show();