It feels like a very stupid question but i cant figure out how to close my dialog when the user clicks a radiobutton in the dialog.. (so something like alert.dismiss() in the onClick)
final CharSequence[] items = {"Nederland", "België", "Denemarken", "Duitsland", "Frankrijk", "Italië", "Luxemburg", "Oostenrijk", "Verenigd Koningkrijg", "Zweden"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Selecteer het land");
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Button country = (Button) findViewById(R.id.land_fac_but);
country.setText(items[item]);
}
});
AlertDialog alert = builder.create();
alert.show();
Just add dialog.dismiss()
inside your OnClickListener
:
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Button country = (Button) findViewById(R.id.land_fac_but);
country.setText(items[item]);
dialog.dismiss();
}
});
If you want to dismiss it as soon as an item is clicked. Else you might want to look into creating a more custom Dialog
by extending AlertDialog
.
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