2017-04-09 9 views
0

同じ質問に6つのRadioButtonがあり、いくつかのRadioGroupに配置する必要があります。しかし、これらのRadioButtonsは一部のLinearLayoutsにあります。私は各RadioButtonに1つのRadioGroupを配置しようとしましたが、私はそれが動作するために何をする必要があるのか​​分かりません。RadioGroup内のLineaLayoutにあるRadioButtonの配置方法

enter image description here

tab_layout_a.xml

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    android:layout_gravity="bottom" 
    android:layout_weight="1" 
    android:orientation="vertical"> 

        <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:layout_weight="1" 
         android:orientation="horizontal"> 

          <RadioButton 
           android:id="@+id/tipoPackRadio1" 
           android:layout_width="match_parent" 
           android:layout_height="wrap_content" 
           android:layout_gravity="center" 
           android:layout_weight="1" 
           android:text="Normal" 
           android:textSize="@dimen/radiobuttons_font_sz" /> 

          <RadioButton 
           android:id="@+id/tipoPackRadio2" 
           android:layout_width="match_parent" 
           android:layout_height="wrap_content" 
           android:layout_gravity="center" 
           android:layout_marginLeft="5dp" 
           android:layout_marginRight="5dp" 
           android:layout_weight="1" 
           android:text="Gilda" 
           android:textSize="@dimen/radiobuttons_font_sz" /> 

         <LinearLayout 
          android:layout_width="match_parent" 
          android:layout_height="50dp" 
          android:layout_weight="0.9" 
          android:orientation="horizontal"> 

           <RadioButton 
            android:id="@+id/tipoPackRadio3" 
            android:layout_width="match_parent" 
            android:layout_height="wrap_content" 
            android:layout_gravity="center" 
            android:layout_marginLeft="0dp" 
            android:layout_weight="1" 
            android:text="Aged Pack \n(cheese/salve)" 
            android:textSize="@dimen/radiobuttons_font_sz" /> 

         </LinearLayout> 

        </LinearLayout> 

        <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:layout_gravity="bottom" 
         android:layout_weight="1" 
         android:orientation="horizontal"> 


          <RadioButton 
           android:id="@+id/tipoPackRadio4" 
           android:layout_width="match_parent" 
           android:layout_height="wrap_content" 
           android:layout_gravity="center" 
           android:layout_marginRight="0dp" 
           android:layout_weight="1" 
           android:text="Fellowship" 
           android:textSize="@dimen/radiobuttons_font_sz" /> 

          <RadioButton 
           android:id="@+id/tipoPackRadio5" 
           android:layout_width="match_parent" 
           android:layout_height="wrap_content" 
           android:layout_gravity="center" 
           android:layout_marginLeft="5dp" 
           android:layout_marginRight="5dp" 
           android:layout_weight="1" 
           android:text="Fertilizer" 
           android:textSize="@dimen/radiobuttons_font_sz" /> 

         <LinearLayout 
          android:layout_width="match_parent" 
          android:layout_height="match_parent" 
          android:layout_weight="0.9" 
          android:orientation="horizontal"> 

           <RadioButton 
            android:id="@+id/tipoPackRadio6" 
            android:layout_width="match_parent" 
            android:layout_height="wrap_content" 
            android:layout_gravity="center" 
            android:layout_marginLeft="0dp" 
            android:layout_weight="1" 
            android:text="Aged Pack \n(honey)" 
            android:textSize="@dimen/radiobuttons_font_sz" 
            android:visibility="visible" /> 

         </LinearLayout> 
        </LinearLayout> 

       </LinearLayout> 

答えて

3

の他の選択がリセットされますanyradioボタンをクリックすることで、

class MyActivity extends Activity { 

RadioButton _Rone, _Rtwo, _Rthree; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 

//after setContentView(.....) 

    _Rone = (RadioButton) findViewById(R.id.radio_one); 
    _Rtwo = (RadioButton) findViewById(R.id.radio_two); 
    _Rthree = (RadioButton) findViewById(R.id.radio_three); 

    _Rone.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      _Rone.setChecked(true); 
      _Rtwo.setChecked(false); 
      _Rthree.setChecked(false); 
     } 
    }); 

    _Rtwo.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      _Rone.setChecked(false); 
      _Rtwo.setChecked(true); 
      _Rthree.setChecked(false); 
     } 
    }); 

    _Rthree.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      _Rone.setChecked(false); 
      _Rtwo.setChecked(false); 
      _Rthree.setChecked(true); 
     } 
    }); 
// do code here 
}` 

...このソリューションをお試しください。

+0

私はLinearLayoutsが必要なのでこれを行うことはできません –

+0

このソリューションを試してください..それは動作します – deejay

+0

@KeltonHolandaFonteneleこのコードはどんなタイプのレイアウトでも動作します。 RadioButtonsに直接アクセスするだけです。 –

関連する問題