Say I have a 'SWITCH BUTTON' and a regular 'BUTTON'. If the SWITCH BUTTON button is on, then NORMAL BUTTON is on. If the SWITCH key is off, the NORMAL BUTTON is disabled.
Under these conditions, is it more efficient to add and remove a NORMAL BUTTON event listener to free up memory consumption when it is turned off?
For example:
public void sample() {
Switch switchButton = (Switch) findViewById(R.id.sample_switch);
switchButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
Button normalButton = (Button) findViewById(R.id.sample_button);
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
normalButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
} else
normalButton.setOnClickListener(null);
}
});
}
source
share