簡體   English   中英

顯示來自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 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>

爪哇

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM