CLICK HERE TO EARN MONEY FREE

Wednesday, November 28, 2012

AlertDialog in androd


 A box that appears on a display screen to present
information or request input. Typically, dialog boxes are
temporary -- they disappear once you have entered the
requested information.



Assign Variables

AlertDialog.Builder builder;
AlertDialog alert;
Button button;

 Dialog Box
Title
Message
Option Button


Building the dialog


builder = new AlertDialog.Builder(this);
builder.setTitle("Question!");
builder.setMessage("Are you sure?");
builder.setCancelable(false);
builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {


@Override

public void onClick(DialogInterface dialog, int which) {


// TODO Auto-generated method stub


Toast.makeText(getApplicationContext(), "Byebye!",



Toast.LENGTH_SHORT).show();


finish();

}
});

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


@Override

public void onClick(DialogInterface dialog, int which) {


// TODO Auto-generated method stub


Toast.makeText(getApplicationContext(), "Exit Canceled",



Toast.LENGTH_SHORT).show();


dialog.cancel();

}
});

 Creating the dialog

alert = builder.create();


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

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
alert.show();
}
});

0 comments:

Post a Comment

 

TEKONOLOGY Copyright © 2011 -- Template created by TEKONOLOGY -- Powered by Blogger