显示来自 RadioGroup 中选定索引的按钮文本

Display button text from from selected index in a RadioGroup

我让我的应用程序使用用户通过表单输入的信息自动填充电子邮件。当我尝试显示他们选择的索引时,它给了我

android.support.v7.widget.AppCompatRadioButton {2d57753c VFED..C. ...P..ID 705,0-903,96#7f0d0056 应用程序:id/RejectRadio}

这是正确的 ID 等等,但我宁愿它只说 "Reject",或者如果选择了另一个按钮则只说 "Accept"。我该怎么做。

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();

获取单选按钮的索引后,您需要获取文本:

RadioButton btn = (RadioButton) radioButtonID.getChildAt(radioButtonId);
fAnswer = (String) btn.getText();

您要获取单选按钮的文本吗?

 RadioButton btn = (RadioButton) ApproveorReject.getChildAt(index);
 fAnswer  = (String) btn.getText();