I can't create an onCheckedChanged listener for my RadioGroup

匆匆过客 提交于 2019-12-02 09:00:25

Make sure you imported the correct package import android.widget.RadioGroup.OnCheckedChangeListener; then the @Override will be correct

Jagadesh Seeram

You can directly add the listener with the ClassName

 radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            // TODO Auto-generated method stub

        }
    });

If, for example, you already are using a CompoundButton and associated OnCheckedChangeListener, you will not be able to import the RadioGroup class, but will still be able to access it directly using this solution.

I think you have imported the wrong package.

You should import android.widget.RadioGroup.OnCheckedChangeListener

instead of android.widget.CompoundButton.OnCheckedChangeListener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!