【发布时间】:2014-05-30 02:59:35
【问题描述】:
我在 Android Studio 中工作并尝试获取所选单选按钮的 ID,然后将 ID 存储在字符串中。这可能吗?
我尝试用 .getId() 替换下面的 .getText() 方法,但它不允许我将其存储为字符串:
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkedId)
{
RadioButton checkedRadioButton = (RadioButton) findViewById(checkedId);
String text = checkedRadioButton.getText().toString();
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
}
});
【问题讨论】:
标签: java android android-studio