Search This Blog

22 April 2010

Alert Dialogs

Using our last example as a starting point, we are going to add an alert dialog.  Make sure to do a 'mvn install' before we get started so your IDE doesn't try to guess where R.layout.main is.

Open Let's modify the onCreate method:

    public void onCreate(Bundle savedInstanceState) {

        AlertDialog dialog = new AlertDialog.Builder(this).create();
        dialog.setTitle("It's an alert!");
        dialog.setMessage("This alert has a message.");
        dialog.setButton("OK", new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialogInterface, int i) {

Redeploy (mvn clean install) and you'll see the alert when you launch your app.

1 comment:

  1. There is also a dialog.setButton2 and dialog.setButton3. Surprisingly, Button3 seems to be in the middle.