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.