我經歷了這個并找到了一個共同的答案,即
int selectedId = radioGroup.getCheckedRadioButtonId();
radioButton = (RadioButton) findViewById(selectedId);
Toast.makeText(MyAndroidAppActivity.this,
radioButton.getText(), Toast.LENGTH_SHORT).show();
但是如何使用視圖系結來獲取文本呢?
uj5u.com熱心網友回復:
你可以這樣做:
編輯:
int id = binding.radioGroup.getCheckedRadioButtonId();
RadioButton radioButton = binding.getRoot().findViewById(id);
//Then get the radio button's text
Toast.makeText(MyAndroidAppActivity.this,
radioButton.getText(), Toast.LENGTH_SHORT).show();
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/418199.html
標籤:
上一篇:如何添加滑動以重繪我的代碼?
