Kus*_*rma 2 android radio-group radio-button android-studio android-viewbinding
我经历过这个并找到了一个共同的答案,即
int selectedId = radioGroup.getCheckedRadioButtonId();
radioButton = (RadioButton) findViewById(selectedId);
Toast.makeText(MyAndroidAppActivity.this,
radioButton.getText(), Toast.LENGTH_SHORT).show();
Run Code Online (Sandbox Code Playgroud)
但是如何使用视图绑定获取文本呢?
你可以这样做:
编辑:
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();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1718 次 |
| 最近记录: |