Monday, August 23, 2010

AlertDialog with single selection & no radio button

Current Android version AlertDialog.Builder default behavior of "setSingleChoiceItems" creates a list with radio buttons from which you can select.

I wanted to get this list without the radio button. After digging a bit in AlertDialog.Builder & AlertController.AlertParams I found the solution: instead of using setSingleChoiceItems use setAdapter.


ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.select_dialog_item, itemActionsList);
dialog.setAdapter(adapter,
new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// Do something
arg0.dismiss();
}
});

3 comments:

sam said...

Thanks

Christian Kaiser said...

But then, android.R.layout.select_dialog_item is wrong, should be android.R.layout.simple_list_item_1

Prabhakar Kumar said...

Thanks bro.