2012-02-29 11 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は1つのラジオボタンのみを表示します。 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

+0

Stupid !! 'RadioGroup'に' android:orientation = "horizo​​ntal"を使っていました。 'android:orientation =" vertical "' –

答えて

2

ラジオグループと線形レイアウトの両方でコンテンツをラップするように高さを変更してください。

+0

ありがとう、私はそれを修正した、それは問題ではなかった。 +1 –

+0

受け入れられる回答? – FabianCook

+0

質問の私のコメントを参照してください。それに応じてあなたの答えを編集するなら、私はそれを受け入れるでしょう。 :) –

関連する問題