Android AlertDialog.Builder 带有单选按钮和微调器
Android AlertDialog.Builder with Radiobutton and Spinner
以下代码显示带有 AlertDialog 构建器的单选按钮。我试图弄清楚是否可以在单选按钮下方添加一个微调器?这是否受支持,或者 AlertDialog 可以用于单选按钮或 Spinner 但不能同时用于两者?
// listItems has values "z","y","x"
final CharSequence[] avail_types = listItems.toArray(new CharSequence[listItems.size()]);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(" Select your choice ");
builder.setSingleChoiceItems(avail_types, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
selected_item = item;
}
});
builder.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//do_yes()
}
});
AlertDialog alert = builder.create();
alert.show();
I was trying to figure out is it possible to add a Spinner below the
radio-button ?
不,使用 setSingleChoiceItems
方法的默认实现无法在 AlertDialog 布局中添加其他视图。
Is this supported or AlertDialog can be used either for radio-button
or Spinner but not both?
不,但您可以使用自定义布局为其创建自定义 AlertDialog
,其中 ListView
和 ListView 行布局包含 RadioButton
和 Spinner
。
编辑:
请参阅以下教程以创建具有自定义布局的 AlertDialog:
以下代码显示带有 AlertDialog 构建器的单选按钮。我试图弄清楚是否可以在单选按钮下方添加一个微调器?这是否受支持,或者 AlertDialog 可以用于单选按钮或 Spinner 但不能同时用于两者?
// listItems has values "z","y","x"
final CharSequence[] avail_types = listItems.toArray(new CharSequence[listItems.size()]);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(" Select your choice ");
builder.setSingleChoiceItems(avail_types, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
selected_item = item;
}
});
builder.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//do_yes()
}
});
AlertDialog alert = builder.create();
alert.show();
I was trying to figure out is it possible to add a Spinner below the radio-button ?
不,使用 setSingleChoiceItems
方法的默认实现无法在 AlertDialog 布局中添加其他视图。
Is this supported or AlertDialog can be used either for radio-button or Spinner but not both?
不,但您可以使用自定义布局为其创建自定义 AlertDialog
,其中 ListView
和 ListView 行布局包含 RadioButton
和 Spinner
。
编辑:
请参阅以下教程以创建具有自定义布局的 AlertDialog: