I’m struggling with this problem for a day now, and I just can’t figure out how to solve it.
So, I have an AlertDialog where I want to display a list of items to choose. These items must have multiple text views and so, so I cannot rely on a simple setMultiChoiceItems() on builder using default format.
I use my custom ArrayAdapter here, by doing this:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Choose details to display");
builder.setAdapter(new ContactAdapter(this, 0, items), null);
I thought I could use an OnClickListener as the second paramtere of setAdapter but that closes the dialog after choosing one option.
Trying to fix this I added a setOnClickListener() inside my ContactsAdapter when I fetch the row layout, like this:
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.contact_row, null);
view.setOnClickListener(new OnClickListener() {....}
This works, but I stop getting the highlight when I click a row, which I really don’t want.
Any ideas how to solve this? I know I could use a ListActivity and that would be easy to solve, but I really want to do this in a dialog. Thanks!
If you think it’d be easy to do using a
ListActivity, why not do that and use the dialog theme usingsetTheme(android.R.style.Theme_Dialog)orandroid:theme="@android:style/Theme.Dialog"for the Activity in the application manifest?If you’re targeting Honeycomb or Ice Cream Sandwich (Android 3.0+), it’s called
setTheme(android.R.style.Theme_Holo_Dialog)andandroid:theme="@android:style/Theme.Holo.Dialog".