Not Disabling the EditText
on execution in onCreate()
. But, when clicking on CheckBox
the method executes once and then stops execution again.
Anyone help to find the Answer
public void EXtraWorkCalc(){
extraworkCheck = (CheckBox)findViewById(R.id.workCheck);
extraworkCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (!compoundButton.isChecked()) {
extraSpace = (EditText) findViewById(R.id.extraWidthEtxt);
extraSpace.setEnabled(false);
extraSpace.setBackgroundColor(Color.LTGRAY);
} else
extraSpace.setEnabled(true);
extraSpace.setBackgroundColor(Color.WHITE);
}
});
}
You are initializing the EditText
in inside the checkBox
setOnCheckedChangeListener
. That's why it's not working.
Initialize your EditText
(extraSpace) in oncreate()
or before calling EXtraWorkCalc()
method.
Move this line to onCreate()
:
extraSpace = (EditText) findViewById(R.id.extraWidthEtxt);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.