Reputation: 4708
I need to show an AlertDialog
with a few custom rows. These rows should have a radio button on the right, and the choice mode should be single mode (hence radio buttons).
What I have:
ArrayList<HashMap<String, String>> it = new ArrayList<HashMap<String,String>>();
HashMap<String, String> map;
map = new HashMap<String, String>();
map.put("asd", "test1");
it.add(map);
map = new HashMap<String, String>();
map.put("asd", "test2");
it.add(map);
map = new HashMap<String, String>();
map.put("asd", "test3");
it.add(map);
SimpleAdapter sa = new SimpleAdapter(context, it, R.layout.dialog_row, new String[] { "asd" }, new int[] { android.R.id.text1 });
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setSingleChoiceItems(sa, -1, null);
// here are added positive and negative buttons
builder.show();
xml for dialog_row
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/rowIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/rh_3" />
<CheckedTextView
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="?listPreferredItemHeightSmall"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:gravity="center_vertical"
android:paddingLeft="?listPreferredItemPaddingLeft"
android:paddingRight="?listPreferredItemPaddingRight"
android:textAppearance="?textAppearanceListItemSmall" />
</LinearLayout>
The AlertDialog
shows up as I expect - but when I click an item, the radio button remains unchecked. Why is this?
Upvotes: 0
Views: 2854
Reputation: 4708
I found a working solution here: https://stackoverflow.com/a/3281239/554002
Basically I had to make a custom ArrayAdapter
and just use a CheckedTextView
as the only element in my layout xml instead of the elements posted above.
Upvotes: 1