我曾经经历过this https://stackoverflow.com/questions/18179124/android-getting-value-from-selected-radiobutton并找到了一个共同的答案,即
int selectedId = radioGroup.getCheckedRadioButtonId();
radioButton = (RadioButton) findViewById(selectedId);
Toast.makeText(MyAndroidAppActivity.this,
radioButton.getText(), Toast.LENGTH_SHORT).show();
但是如何使用视图绑定获取文本呢?
你可以这样做:
EDIT:
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();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)