RSS

Display an Alert Dialog

23 Jan
package com.my.option;

import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.DialogInterface;
 import android.os.Bundle;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.Button;

public class OptionMenuActivity extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);

Button b = (Button) findViewById(R.id.button1);
 b.setOnClickListener(new OnClickListener() {

@Override
 public void onClick(View arg0) {
 AlertDialog.Builder builder = new AlertDialog.Builder(OptionMenuActivity.this);
 builder.setMessage("Do you really need to exit?");
 builder.setCancelable(false);

builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

@Override
 public void onClick(DialogInterface arg0, int arg1) {
 OptionMenuActivity.this.finish();

}
 });

builder.setNegativeButton("No", new DialogInterface.OnClickListener() {

@Override
 public void onClick(DialogInterface dialog, int arg1) {
 dialog.cancel();

}

});

AlertDialog alert = builder.create();
 alert.show();
 }
 });
 }

}

Advertisements
 
Leave a comment

Posted by on January 23, 2012 in Android

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: