第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在Android中獲取RadioGroup的選定索引

如何在Android中獲取RadioGroup的選定索引

蝴蝶不菲 2019-12-10 10:17:06
是否有一種簡(jiǎn)單的方法來獲取Android中RadioGroup的選定索引,還是我必須使用OnCheckedChangeListener來偵聽更改并擁有保存最后選定索引的內(nèi)容?范例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>如果用戶選擇option 3我要獲取索引,則2。
查看完整描述

3 回答

?
Qyouu

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超11個(gè)贊

您應(yīng)該能夠執(zhí)行以下操作:


int radioButtonID = radioButtonGroup.getCheckedRadioButtonId();

View radioButton = radioButtonGroup.findViewById(radioButtonID);

int idx = radioButtonGroup.indexOfChild(radioButton);

如果RadioGroup包含其他視圖(如TextView),則該indexOfChild()方法將返回錯(cuò)誤的索引。


要在上獲取選定的RadioButton文本RadioGroup:


 RadioButton r = (RadioButton) radioButtonGroup.getChildAt(idx);

 String selectedtext = r.getText().toString();


查看完整回答
反對(duì) 回復(fù) 2019-12-10
?
紅顏莎娜

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超13個(gè)贊

這應(yīng)該工作,


int index = myRadioGroup.indexOfChild(findViewById(myRadioGroup.getCheckedRadioButtonId()));


查看完整回答
反對(duì) 回復(fù) 2019-12-10
  • 3 回答
  • 0 關(guān)注
  • 1021 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)