Myself trying to enable/disable a textfield using checkbox as,
tv = (EditText) findViewById(R.id.tv);
cb = (CheckBox) findViewById(R.id.cb);
tv.setFocusable(false);
tv.setKeyListener(null);
tv.setEnabled(false);
cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
tv.setFocusable(true);
tv.setEnabled(true);
tv.setKeyListener(new DigitsKeyListener(false, true));
} else {
tv.setFocusable(false);
tv.setEnabled(false);
tv.setKeyListener(null);
}
}
}
);
The above code is in onCreate
method. But even when the checkbox checked, the tv.setKeyListener(new DigitsKeyListener(false, true));
doesn't enabling the keys. Where myself missed?
Aucun commentaire:
Enregistrer un commentaire