Working With AlertDialogbox Android- UI Widget


As per the name suggests Alert Dialog Box is same as other programming language . It shows or prompt user that so you really want to exit this application or similar things. Lets Explore – Download Code

1). First of all create new project and in activity_main.xml file their is nothing special but if you want to develop something interesting app then you can customize by your own like on back button press Alert dialog box etc.

2). , I include AlertDialog.Builder class and via its object I set Message , Title and other properties like  two buttons namely yes or no etc . 

package androidarena.alertdialog;

import androidarena.alertdialog.R;

import android.os.Bundle;
import android.content.DialogInterface;
import android.view.Menu;

public class MainActivity extends Activity {

	protected void onCreate(Bundle savedInstanceState) {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setMessage(R.string.dialog_message) .setTitle(R.string.dialog_title);
		builder.setMessage("Do you want to close this app ?")
		    .setPositiveButton("Yeah !", new DialogInterface.OnClickListener() {
		    public void onClick(DialogInterface dialog, int id) {
		    .setNegativeButton("No way", new DialogInterface.OnClickListener() {
		    public void onClick(DialogInterface dialog, int id) {
		    //  Action for 'NO' Button
		AlertDialog alert = builder.create();

	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(, menu);
		return true;


Output – alertdialogboxAny query or customization on this tutorial , feel free to share . Happy Coding :p

Leave a Reply

Your email address will not be published. Required fields are marked *