我創建了一個alertdialog,裡面有倆個radio buttons,當用戶選擇一個選項時,我需要解除alertdialog,但是不知道怎麼解除,請大家的幫忙。
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();
使用下面的代碼:
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();