简体   繁体   中英

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. I try with a null where you select the default button, but it doesn't work. 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.

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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