i have created a alertdialog with two radio buttons in it.when user select an option i need to dismiss the alertdialog but i am not been able to dismiss it.
final CharSequence[] items = {"First Option", "Second Option"};
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Choose an option");
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
}
});
final AlertDialog alert = builder.create();
alert.show();
Can someone help me how to do this.
Thanks
Please try this..
final CharSequence[] items = {"First Option", "Second Option"};
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Choose an option");
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
dialog.dismiss();
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
}
});
final AlertDialog alert = builder.create();
alert.show();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With