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

  • ☆ SUB4SUB CENTER! ☆ spam here

    ☆ SUB4SUB

    22 ŞUBAT 2010
  • уσ ρℓz sυв ιℓℓ sυв вαcқ

    уσ ρℓz

    14 EKİM 2010
  • Matthew Smith

    Matthew Smit

    24 Mayıs 2010