15 Ekim 2017 Pazar

RadioGroup Sınıfı

XML
Şöyle yaparız.
<RadioGroup
  android:layout_width="match_parent"
  android:layout_height="match_parent">


  <RadioButton
    android:text="Filter Search"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/filtersearch"
    android:layout_weight="1"
    android:checked="false"/>
  <RadioButton
    android:text="Trace my activities"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/traceme"
    android:layout_weight="1" />

</RadioGroup>
setOnCheckedChangeListener metodu
Şöyle yaparız.
RadioGroup radG = (RadioGroup) findViewById(R.id.yourRadioGroup);        
radG.setOnCheckedChangeListener(new OnCheckedChangeListener() 
{
  @Override
  public void onCheckedChanged(RadioGroup group, int checkedId) {
    / checkedId is the RadioButton selected
    switch(checkedId) 
    {
      case R.id.hexa:     
      ...
      break;

      case R.id.normal: 
      ...
      break;

    }
  }
});

Hiç yorum yok:

Yorum Gönder