0

I'm trying to make a button that is disabled until you check the checkbox

Button mButton=(Button)findViewById( R.id.registerBut);
    CheckBox mCheckBox= findViewById( R.id.checkBox);

mCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        mButton.setEnabled(isChecked);
    }
});

setOnCheckedChangeListener and CompoundButton buttonView says- "cannot resolve symbol" ,
new OnCheckedChangeListene says - "Invalid method declaration; return type required"

If you could please help me solve this. Thanks in advance :D

Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
Vedo
  • 976
  • 4
  • 21

1 Answers1

0

There is no problem in your code unless you correctly import dependencies.

import android.widget.CheckBox;
import android.widget.CompoundButton;

CheckBox mCheckBox = new CheckBox(this);
mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        // your code
    }
});
Md. Asaduzzaman
  • 14,963
  • 2
  • 34
  • 46