我的应用程序会自动填充一封电子邮件,其中包含用户通过表单输入的信息。当我尝试显示他们选择的索引时,它给了我
android.support.v7.widget.AppCompatRadioButton {2d57753c VFED..C。 ... P..ID 705,0-903,96#7f0d0056 app:id / RejectRadio}
这是正确的ID,但我宁愿只说“拒绝”,或者如果选择其他按钮只是“接受”。我该怎么做呢。
XML
<RadioGroup
android:id="@+id/radiochoice"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/EditTextFeedbackBody"
android:orientation="horizontal">
<RadioButton
android:id="@+id/AcceptRadio"
android:layout_width="wrap_content"
android:layout_marginStart="50dp"
android:layout_height="wrap_content"
android:text="@string/acceptbutton" />
<RadioButton
android:id="@+id/RejectRadio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rejectbutton"
android:layout_marginStart="115dp" />
</RadioGroup>
JAVA
int radioButtonID = radiochoice.getCheckedRadioButtonId();
View radioButton = radiochoice.findViewById(radioButtonID);
int index = radiochoice.indexOfChild(radioButton);
final RadioGroup ApproveorReject = (RadioGroup) findViewById(R.id.radiochoice);
fAnswer = ApproveorReject.getChildAt(index).toString();
答案 0 :(得分:0)
获取单选按钮的索引后,您需要获取文本:
RadioButton btn = (RadioButton) radioButtonID.getChildAt(radioButtonId);
fAnswer = (String) btn.getText();
答案 1 :(得分:0)
您是否想要获取单选按钮的文本?
RadioButton btn = (RadioButton) ApproveorReject.getChildAt(index);
fAnswer = (String) btn.getText();