0
    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 消息。请帮助并指出我是否遗漏或搞砸了任何事情。谢谢是提前。

4

1 回答 1

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; 
}

由于您的代码中没有任何 switch case,因此这两个函数都在执行。所以,做上面的实现,这将帮助你做你需要的......

于 2014-05-26T07:09:26.187 回答