我需要显示AlertDialog
一些自定义行。这些行的右侧应该有一个单选按钮,选择模式应该是单选模式(因此是单选按钮)。
是)我有的:
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 为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>
正如我预期的AlertDialog
那样显示 - 但是当我单击一个项目时,单选按钮保持未选中状态。为什么是这样?