0

I'm trying to set default selected item inside AlertDialog list.

Please see the code below:

final CharSequence[] tools = GetTools(toolTypeIndex);
if (tools.length > 0) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    final int selectedTool = GetToolIndex();

    if(selectedTool>=0)
    {
        builder.setTitle("Select the tool")
            .setSingleChoiceItems(tools, selectedTool,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int item) {
                            ...
                        }
                    })
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                ...
                    }
            })
            .show();
    }
}

But it doesn't works. If selectedTool>=0 then always selected only first item by default. If selectedTool==-1 then no selected items.

It is very strange situation. I read documentation AlertDialog.Builder setSingleChoiceItems but it doesn't help me.

dvlpr
  • 11
  • 4

2 Answers2

0

You may also try custom view in Alert Dialog with listview or this may help you

How can I display a list view in an Android Alert Dialog?

Community
  • 1
  • 1
misman
  • 1,347
  • 3
  • 21
  • 39
  • No, I need list of radiobuttons and DEFAULT selected item (first, second, third or any other) – dvlpr Apr 16 '15 at 07:41
  • Then, you should check this out http://stackoverflow.com/questions/21347661/android-radio-button-in-custom-list-view/21348318#21348318 – misman Apr 16 '15 at 08:09
0

This is the bug in Android. What is your API version?

bask0xff
  • 145
  • 4
  • 13