我需要一个像这样的对话
但我无法找到执行RadioButton
对话框的方法,默认情况下未选择任何选项。我尝试使用null来选择默认按钮,但它不起作用。有什么想法吗?
这是我的代码:
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(titulo)
.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dlgRadiobuttonsListener.seleccionadoRB(DlgRadiobuttons.this, getResources().getStringArray(items)[which]);
}
});
return builder.create();
}
答案 0 :(得分:3)
setSingleChoiceItems的第二个参数是要选择的项的索引,传递-1将使android不选择任何人。
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(titulo)
.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dlgRadiobuttonsListener.seleccionadoRB(DlgRadiobuttons.this, getResources().getStringArray(items)[which]);
}
});
return builder.create();
}