Using ArrayAdapter with AlertDialog and .setAdapter

HSPalm picture HSPalm · Feb 6, 2012 · Viewed 22.6k times · Source

My code goes inside an OnOptionsItemSelected method. I've tried displaying a simple toast and it works fine, so at least I know I'm "getting there".

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_multichoice);
adapter.add("whatever data1");
adapter.add("whatever data2");
adapter.add("whatever data3");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("whatever title");
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int item) {

    }
});

The problem is that there's no alert dialog. I've tried constructing an alert dialog with simple arrays, which works.

Answer

Heiko Rupp picture Heiko Rupp · Feb 6, 2012

I think you are missing the

AlertDialog alert = builder.create();
alert.show();