I want to create dialog with simple single choice items. By default, no items are selected. I only want an OK and Cancel button. The OK button must remain disabled until an item is selected. Is there some built-in way of doing this or do I have to create my own custom dialog? This is currently what I have:
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(getString(R.string.lbl_MarkReviewAs))
.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int item)
{
selectedReviewStatusIndex = item;
AlertDialog alertDialog = (AlertDialog)dialog;
alertDialog.getButton(0).setEnabled(true);
}
})
.setPositiveButton(getString(R.string.lbl_ButtonOK), new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
dialog.dismiss();
}
})
.setNegativeButton(getString(R.string.lbl_ButtonCancel), new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
dialog.show();
The problem here is that dialog.getButton(AlertDialog.BUTTON_POSITIVE) returns null. So how do I access the positive button?
I thing best is to subclass ListActivity. Here is example.
To make it nice set style of this activity (in manifest) to some Dialog (best choice is "@android:style/Theme.DeviceDefault.Dialog").
you need show dialog then disable button Positive.
set listener to the Item selected and enable the "OK" Button