how to do alert dialog box activity
I have one button when I click the button it shows the alert dialog box with three options. i am click the first option do开发者_如何学Go something like second and third option. how to do in android. i am very new android can you anyone please help me for this
This is my code
final CharSequence[] items = {"set", "option"};
AlertDialog.Builder builder = new AlertDialog.Builder(ProgramInfoActivity.this);
builder.setTitle("Share the Program");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if( set){
}
else if (option){
}
}});
AlertDialog alert = builder.create();
alert.show();
Thanks
raj.
Here is my code...you can use it with small changes...just add another button and that it. My button Yes open another screen....
AlertDialog ad = new AlertDialog.Builder(this).create();
ad.setButton(DialogInterface.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface ad, int which) {
Intent i = new Intent(PronadjiKlopuActivity.this, TrenutnaLokacija.class);
startActivity(i);
}
});
ad.setButton(DialogInterface.BUTTON_NEGATIVE, "No",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
ad.show();
You have to use setMultiChoiceItems method.
return new AlertDialog.Builder( this )
.setTitle( "Planets" )
.setMultiChoiceItems( _options, _selections, new DialogSelectionClickHandler() )
.setPositiveButton( "OK", new DialogButtonClickHandler() )
.create();
Following reference will help you:
http://labs.makemachine.net/2010/03/android-multi-selection-dialogs/
精彩评论