I can't create an onCheckedChanged listener for my RadioGroup

前端 未结 3 1937
天命终不由人
天命终不由人 2021-01-26 05:29

I\'m trying to create an onCheckedChanged Listener for my RadioGroup, but eclipse is throwing erros at me. this is the code

<         


        
相关标签:
3条回答
  • 2021-01-26 05:52

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

    0 讨论(0)
  • 2021-01-26 06:05

    I think you have imported the wrong package.

    You should import android.widget.RadioGroup.OnCheckedChangeListener

    instead of android.widget.CompoundButton.OnCheckedChangeListener

    0 讨论(0)
  • 2021-01-26 06:07

    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.

    0 讨论(0)
提交回复
热议问题