in Android Code Tips

Simple AlertDialog tutorial

How to create a AlertDialog to display a message in Android:

final AlertDialog alertDialog = new AlertDialog.Builder(YourActivity.this).create();
alertDialog.setTitle(getString(R.string.app_name));
alertDialog.setIcon(R.drawable.icon);
alertDialog.setMessage("Your message here");
alertDialog.setButton("Back", new DialogInterface.OnClickListener() {
		public void onClick(DialogInterface dialog, int which) {
			alertDialog.dismiss();
		}
});
alertDialog.show();
Share