我最近在我的android项目中集成了蝴蝶刀,现在我正在尝试使用@OnCheckedChanged注释来进行无线电分组。但却犯了个错误不给回电话。那么,调用和获取checkedId的正确方法是什么,或者这个方法只适用于无线电按钮,而不是用于无线电分组。
@OnCheckedChanged(R.id.gendergroupid)
void onGenderSelected(RadioGroup group, int checkedId){
switch(checkedId){
case R.id.maleid:
maleid.setEnabled(true);
maleid.setChecked(true);
break;
case R.id.femaleid:
femaleid.setEnabled(true);
femaleid.setChecked(true);
break;
case R.id.bothid:
bothid.setEnabled(true);
bothid.setChecked(true);
break;
}
}
给了我错误
BloError:(89,10)错误:无法匹配@OnCheckedChanged方法参数。
参数#1: android.widget.RadioGroup不匹配任何侦听器参数
参数#2: int与任何侦听器参数不匹配
方法可能有最多2个参数:
android.widget.CompoundButton布尔
这些可以按任何顺序列出,但将从顶部搜索到bottom.ckquote。
发布于 2017-06-16 04:34:37
这对我来说很管用
@OnCheckedChanged({R.id.radio_button1, R.id.radio_button2})
public void onRadioButtonCheckChanged(CompoundButton button, boolean checked) {
if(checked) {
switch (button.getId()) {
case R.id.radio_button1:
// do stuff
break;
case R.id.radio_button2:
// do stuff
break;
}
}
}
https://stackoverflow.com/questions/43869810
复制相似问题