SORU
22 HAZİRAN 2011, ÇARŞAMBA


Nasıl Android bir RadioGroup seçilen dizin almak için

Android bir RadioGroup seçilen dizin almak için kolay bir yolu var ya OnCheckedChangeListener için değişikliklerini kullanmak zorunda mıyım ve son dizin seçili tutan bir şey var mı?

örnek xml:

<RadioGroup android:id="@ id/group1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
    <RadioButton android:id="@ id/radio1" android:text="option 1" android:layout_width="wrap_content" android:layout_height="wrap_content" />
    <RadioButton android:id="@ id/radio2" android:text="option 2" android:layout_width="wrap_content" android:layout_height="wrap_content" />
    <RadioButton android:id="@ id/radio3" android:text="option 3" android:layout_width="wrap_content" android:layout_height="wrap_content" />
    <RadioButton android:id="@ id/radio4" android:text="option 4" android:layout_width="wrap_content" android:layout_height="wrap_content" />
    <RadioButton android:id="@ id/radio5" android:text="option 5" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</RadioGroup>

eğer bir kullanıcı option 3 seçerse, 2 dizin almak istiyorum.

CEVAP
22 HAZİRAN 2011, ÇARŞAMBA


Böyle bir şey yapmak mümkün olmalıdır:

int radioButtonID = radioButtonGroup.getCheckedRadioButtonId();
View radioButton = radioButtonGroup.findViewById(radioButtonID);
int idx = radioButtonGroup.indexOfChild(radioButton);

Eğer RadioGroup diğer Görünümler (TextView) varsa indexOfChild() yöntem Endeksi yanlış iade edilecektir.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • iZAPPA

    iZAPPA

    16 Temmuz 2010
  • MrChiCity3

    MrChiCity3

    14 NİSAN 2008
  • UKF Dubstep

    UKF Dubstep

    29 NİSAN 2009