RadioGroup r1 = (RadioGroup) view.findViewById(R.id.first);
r1.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
public void onCheckedChanged(RadioGroup group, int checkedId)
{
Utilities.createDebugToastMsg(rootView.getContext(), "clicked on R1");
}
});
RadioGroup r2 = (RadioGroup) view.findViewById(R.id.second);
r2.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
Utilities.createDebugToastMsg(rootView.getContext(), "clicked on R2");
}
});
}
我有两个独立的无线电组,每组包含三个单选按钮。现在我点击哪个单选按钮,两个监听器都被调用,我得到两个toast消息。 请帮助并指出是否有任何我遗漏或搞砸的事情。谢谢你的到来。
答案 0 :(得分:1)
请在代码中加一个开关盒。如下所示:
switch (view.getId()) {
case R.id.first:
your code here for what to do when it is clicked/checked
break;
case R.id.second:
your code here for what to do when it is clicked/checked
break;
}
由于代码中没有任何开关案例,因此两个函数都在执行。所以,做上述实施将帮助你做你需要的......