How to create an AlertDialog
with RadioButton
on the side?
I can create a Dialog
with 3 selection strings using AlertDialog.Builder
, but how 开发者_如何学Gocan I create the one with RadioButton
on the side (i.e. allow only 1 selection)?
Thank you.
I'm not sure if you are using Material Design or not or whether or not you still need this answered after 6 years, but for anybody who may be looking for this, here is the answer
new MaterialDialog.Builder(this)
.title(R.string.which_phone_number)
.items(contactPhonesArr)
.itemsCallbackSingleChoice(0, new MaterialDialog.ListCallbackSingleChoice() {
@Override
public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
//Do really cool things here
dialog.dismiss();
}
return true;
}
})
.positiveText("Choose")
.show();
You can try this:
AlertDialog levelDialog;
// Strings to Show In Dialog with Radio Buttons
final CharSequence[] items = {" Easy "," Medium "," Hard "," Very Hard "};
// Creating and Building the Dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select The Difficulty Level");
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
// Your code
levelDialog.dismiss();
}
});
levelDialog = builder.create();
levelDialog.show();
Use setView()
in AlertDialog.Builder
, perhaps? It is tough to tell what "the one with radio button on the side" means.
精彩评论