2013-03-21 64 views
0

我需要顯示帶有幾個自定義行的AlertDialog。這些行應該在右側有一個單選按鈕,選擇模式應該是單模式(因此單選按鈕)。具有SimpleAdapter和單選模式的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顯示爲我期望 - 但是當我點擊一個項目,單選按鈕保持選中。爲什麼是這樣?

回答

相關問題