作爲我的應用程序的一部分,我必須在radiogroup中創建四個radioButton並獲得單擊的單選按鈕。我編寫了下面的代碼,但是我的selectId屬性給出了當選擇第一個選項時的值2131034181和當第二個選項被選中時2131034182等等,當點擊3和4時單位數值的變化。爲什麼這樣?RadioGroup的getCheckedRadioButtonId()返回2131034181/2/3/4
int selectId=rbg.getCheckedRadioButtonId();
RadioButton selected= (RadioButton) rbg.findViewById(selectId);
String selected_user = (String) selected.getText();
我認爲你正在尋找選中的單選按鈕的指數?如果是,請檢查:http://stackoverflow.com/a/6441097/1911652 – Atul 2016-05-01 10:56:31