Reputation: 4207
Is there a way in Android to display a dialog with a radio button already selected based on environment variable settings?
I wrote the following code. It doesn't seem to have any errors and I'm pretty sure it executes, but when the dialog is displayed, none of the radio buttons are selected:
switch (shape)
{
case SQUARE:
bigCircle.setSelected (false);
smSircle.setSelected (false);
if (size == BIG)
{
bigSquare.setSelected (true);
smSquare.setSelected (false);
}
else
{
bigSquare.setSelected (false);
smSquare.setSelected (true);
}
break;
case CIRCLE:
bigSquare.setSelected (false);
smSquare.setSelected (false);
if (size == BIG)
{
bigCircle.setSelected (true);
smCircle.setSelected (false);
}
else
{
bigCircle.setSelected (false);
smCircle.setSelected (true);
}
}
dialog.show();
Any suggestions??
Thanks,
R.
Upvotes: 0
Views: 597
Reputation: 7357
do you create your own custom layout for your dialog? (i assume that because of variables bigCircle, smSquare...)
take a look at AlertDialog.Builder's method setSingleChoiceItems (ListAdapter adapter, int checkedItem, DialogInterface.OnClickListener listener) maybe that would be better way...
Upvotes: 1
Reputation: 3111
You need custom dialog with the views that you want. May be you can look at the APIDemos->app->alerdialogs-> alert dialog with single choice list. Modify the layout as per your requirement.
You can inflate the custom ui in your dialog which can contain checkbox, radiobuttons or pretty much anything.
Upvotes: 0