Skip to content Skip to sidebar Skip to footer

Android Sdk Override Alertdialog Events

I am instantiating an alert dialog like so: AlertDialog myAlert = new AlertDialog.Builder(myContext).create(); Is there a way to override the OnKeyDown event for this dialog?

Solution 1:

AlertDialog.Builder build=new AlertDialog.Builder(this);
build.setMessage("This is a message, dawg.")
.setPositiveButton("Awesomesauce.", new OnClickListener()
{
    publicvoidonClick(DialogInterface dialog, int id)
    {
        //stuff here
        dialog.dismiss(); //closes the window
    }
};
AlertDialog myAlert=build.create();
myAlert.show();

You can also add a .setNegativeButton() or .setNeutralButton() to change the neutral/negative buttons, too.

The Android SDK doc for it is here.

Post a Comment for "Android Sdk Override Alertdialog Events"