Android - 警报对话框强制关闭

时间:2015-01-25 14:08:42

标签: android alertdialog

我想在下面显示警告对话框,但强行关闭,我对上下文应该是什么有点困惑。 单击图像时会显示此对话框。

AlertDialog.Builder builder = new AlertDialog.Builder(
getApplicationContext(), R.style.TitleDialog);
builder.setTitle("Sorry for Inconvinience");
builder.setMessage("You need to install MX Player or VLC Media Player");
AlertDialog alert = builder.create();
alert.show();

我是初学者,任何帮助将不胜感激 完整的onclicklistener

ib2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (isInternetPresent) {
                try {
                    startActivity(i2);
                } catch (Exception e) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(Main.this);
                    builder.setTitle("Sorry for Inconvinience");
                    builder.setMessage("You need to install MX Player or VLC Media Player, here is the link: ");
                    AlertDialog alert = builder.create();
                    alert.show();

                }
            } else {
                Toast.makeText(getApplicationContext(),
                        "Please check your Internet Connection.",
                        Toast.LENGTH_LONG).show();
            }
        }
    });

1 个答案:

答案 0 :(得分:2)

  AlertDialog.Builder builder = new AlertDialog.Builder(Activity.this);
        builder.setTitle("Sorry for Inconvinience");
        buildersetMessage("You need to install MX Player or VLC Media Player");
       .show();

以上代码应该有效。 我不知道是什么

getApplicationContext(), R.style.TitleDialog);

虽然用于。