2016-04-22 9 views
-1

私は間違っていることを教えてください、私はラジオグループを追加して、GridLayoutを追加してラジオボタンを2x2形式の行列に整列させ、それはうまく整列しましたが、ラジオボタンを選択すると、以前に選択したオプションの選択を解除していないという問題があります。どうすればこれを達成できますか?2x2ラジオボタンをアンドロイドのグループに割り当てる方法

All radio buttons are getting selected. None of them are deselecting upon changing selection of radio button. Please suggest me any approach. 

Thanks 

Please check attached image for reference

<RadioGroup 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <GridLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

      <RadioButton 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="New RadioButton" 
       android:id="@+id/radOption1" 
       android:layout_row="0" 
       android:layout_column="0" 
       android:padding="5dp" /> 

      <RadioButton 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="New RadioButton" 
       android:id="@+id/radOption2" 
       android:layout_row="0" 
       android:layout_column="1" 
       android:padding="5dp" /> 

      <RadioButton 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="New RadioButton" 
       android:id="@+id/radOption3" 
       android:layout_row="1" 
       android:layout_column="0" 
       android:padding="5dp" /> 

      <RadioButton 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="New RadioButton" 
       android:id="@+id/radOption4" 
       android:layout_row="1" 
       android:layout_column="1" 
       android:padding="5dp" /> 

    </GridLayout> 
</RadioGroup> 

答えて

1

RadioGroup基本的に、あなたのRadioButtonsを揃えることができ、その中LinearLayoutです。それはあなたの例に何か(GridLayout)を格納できる汎用layoutのようではなく、あなたが階層に置くRadioButtonsを扱います。

TLDR:RadioGroupRadioButtonsを水平または垂直に揃えることができます。LinearLayoutです。

あなたが行う必要があるものは、questionに記載されています。

関連する問題