简体   繁体   English

没有选择默认的单选按钮

[英]No default Radio button selected

I need a dialog like this 我需要这样的对话框

在此处输入图片说明

but I can't find the way to do a RadioButton dialog with no option selected by default. 但我找不到默认不选择任何选项的“ RadioButton对话框的方法。 I try with a null where you select the default button, but it doesn't work. 我尝试使用null来选择默认按钮,但是它不起作用。 Any ideas? 有任何想法吗?

Here is my code: 这是我的代码:

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();        
}

The second parameter of setSingleChoiceItems is the index of the item to be selected, passing -1 will make android to not select anyone. 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();

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM