Simple Alert Dialog Popup with Title, Message, Icon and Button

6 votes · 1 comment

A quick a simple Alert Dialog Popup with Title, Message, Icon and Button

Don't forget to import add the imports

import android.app.AlertDialog; import android.content.DialogInterface;

raw ·
copy
· download
AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("Title"); alertDialog.setMessage("Message"); alertDialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // TODO Add your code for the button here. } }); // Set the Icon for the Dialog alertDialog.setIcon(R.drawable.icon); alertDialog.show();
Add a comment

1 Comment

very useful thanks

Reply · Nov. 2, 2011, 8:22 a.m.