Skip to content Skip to sidebar Skip to footer

Alert Box In Android Doesn't Let Me To Click, Just Directly Performs The Action

I've a button upon clicking should display an alertdialog box containing just 'OK' button and upon clicking should go to another activity. But this dialog box appears for a few sec

Solution 1:

I don't see what the problem is. A few days ago, I tried to include an AlertDialog myself. I saw that there are a lot of deprecated methods. I ended up using the code below. Try this if you like

AlertDialog ad=new AlertDialog.Builder(this).create();
        ad.setTitle(R.string.app_name);
        ad.setMessage("MESSAGE");
        ad.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
            publicvoidonClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }}); 
        ad.show();

Solution 2:

Heres an idea, lets see if your alertDialogs onClick is even being called. This will tell you if your problem is with the alert dialog or with something else. You should be able to copy and paste this into your app and then just call showAlertDialog(); from where ever you want. Post the code where your alertDialog is called from.

publicvoidshowAlertDialog()
{

         AlertDialog.BuilderalertDialogBuilder=newAlertDialog
            .Builder(YourActivity.this);
     alertDialogBuilder.setTitle("Look at me!");
     alertDialogBuilder
            .setMessage("Im an alert dialog")
            .setCancelable(true)
            .setNegativeButton("Okay",newDialogInterface.OnClickListener() 
            {
                publicvoidonClick(DialogInterface dialog,int id) 
                {

                    Toast.makeText(YourActivity.this, "Alert dialog onClick",   
                                    Toast.LENGTH_SHORT).show();   

                    dialog.dismiss();

                }
            }
        );

    AlertDialogalertDialog= alertDialogBuilder.create();
    alertDialog.show();
}

Post a Comment for "Alert Box In Android Doesn't Let Me To Click, Just Directly Performs The Action"