Friday, June 17, 2011

Making a message box in Android

Turns out that making a simple message box in Android is just complicated. So here's a very useful snippet:


public void messageBox(String title, String message) {
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(MyActivity.this).create();
alertDialog.setTitle(title);
alertDialog.setMessage(message);
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

dialog.cancel();

}
});
alertDialog.show();

}