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

  • BiGSH0TROB

    BiGSH0TROB

    7 NİSAN 2011
  • Good Creative Academy

    Good Creativ

    19 Kasım 2009
  • wowchick16

    wowchick16

    17 Mart 2007