In android, we can make simple dialog using AlertDialog.
I make simple button program for alertdialog test.
This is program's layout for alertdialog test.
Simple!! I make 3 buttons.
First button is one button alertdialog.
Second button is two buttons alertdialog.
Third button is three buttons alertdialog.
If you click to first button(one button alertdialog test), you can see this dialog.
If you click to second button(two buttons alertdialog test), you can see this dialog.
If you click to third button(three buttons alertdialog test), you can see this dialog.
This is JAVA code 1 button.
- AlertDialog.Builder ad=new AlertDialog.Builder(this);
- ad.setTitle("1 button").setMessage("This is one button dialog.").setNeutralButton("check",new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- Toast.makeText(getApplicationContext(), "Test end!!", Toast.LENGTH_SHORT).show();
- }
- }).create().show();
setTitle is alertdialog's title text.
setMessage is alertdialog's message text.
setNutralButtun is alertdialog's button.
button's method is
setPositiveButton(CharSequence
text, OnClickListener
listener)
setNegativeButton(CharSequence
text, OnClickListener
listener)
setNeutralButton(CharSequence
text, OnClickListener
listener)
CharSequence text is button's name.
OnClickListener listener is alertdialog button's listener
create() is dialog create.show() is dialog show.
This is 2buttons
- ad.setTitle("2 button").setMessage("This is two button dialog.").setPositiveButton("OK",newDialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- Toast.makeText(getApplicationContext(), "You Click to OK!!", Toast.LENGTH_SHORT).show();
- }
- }).setNegativeButton("NO", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Toast.makeText(getApplicationContext(), "You Click to No!!", Toast.LENGTH_SHORT).show();
- }
- }).create().show();
And 3buttons
- ad.setTitle("3 button").setMessage("This is three button dialog.").setPositiveButton("YES",newDialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- Toast.makeText(getApplicationContext(), "You Click to YES!!", Toast.LENGTH_SHORT).show();
- }
- }).setNegativeButton("NO", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Toast.makeText(getApplicationContext(), "You Click to No!!", Toast.LENGTH_SHORT).show();
- }
- }).setNeutralButton("cancel", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Toast.makeText(getApplicationContext(), "You Click to CANCEL!!", Toast.LENGTH_SHORT).show();
- }
- }).create().show();
No comments:
Post a Comment