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