2012-02-29 41 views
0

我試圖在AlertDialog中設置一個RadioGroup。我爲此使用了以下構造。AlertDialog中的RadioGroup:只顯示單個RadioButton

new AlertDialog.Builder(this) 
      .setTitle("Set icon for " + item_cursor.getString(1)) 
      .setView(radioGroupView) 
      .setPositiveButton("Ok", 
        new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, 
         int whichButton) { 
        RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radiogroup); 
        int checkedRadioButton = 0; 
        try { 
         checkedRadioButton = radioGroup.getCheckedRadioButtonId(); 
        } catch (Exception e) { 
         e.printStackTrace(); 
        } 
        int i =0; 
        switch (checkedRadioButton) { 
        case R.id.a2s : 
        datasource.updateIcon(i,itemid); 
        break; 
        case R.id.android: i=1; 
        datasource.updateIcon(i,itemid); 
        break; 
        } 
       } 
      }).setNegativeButton("Cancel", 
      new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, 
         int whichButton) { 
        // Canceled. 
       } 
      }).show(); 

但alertDialog只顯示一個Radiobutton。以下是XML seticon.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:orientation="vertical"> 
    <RadioGroup android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:orientation="horizontal" 
     android:id="@+id/radiogroup"> 
     <RadioButton android:id="@+id/android" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" 
      android:text="Android" /> 
     <RadioButton android:id="@+id/a2s" android:layout_width="fill_parent" 
      android:layout_height="wrap_content" android:text="Argen2Stone ROM" /> 
    </RadioGroup> 
</LinearLayout> 

爲什麼會發生這種情況?

+0

哪裏是你的radiogroupview的定義 – L7ColWinters 2012-02-29 01:51:24

+0

愚蠢的!我爲'RadioGroup'使用'android:orientation =「horizo​​ntal」'。它應該是'android:orientation =「vertical」' – 2012-02-29 01:51:29

回答

2

嘗試更改高度以包裹收音機組以及線性佈局上的內容。

+0

謝謝,我修正了它,這不是問題。 +1 – 2012-02-29 01:52:05

+0

接受答案? – FabianCook 2012-02-29 01:54:49

+0

請參閱我對問題的評論。如果你相應地編輯你的答案,我會接受它。 :) – 2012-02-29 02:05:53

相關問題