I have a couple of dynamically created EditText fields.
I am trying to disable the fields if the value in another field doesn't match certain criteria.
The issue is that if other criteria is met, the field is disabled properly by setting setEnabled(false);
.
Essentially in a part number field, we check if the part number requires a serial number or a lot number. If the part requires a serial number, the serial number field displays an error, the lot number field is disabled, and the quantity field is set to "1" and disabled If a lot number is required, the lot number field shows an error and the serial number field is disabled. This works as intended.
public void onTextChanged(@NotNull EditText target, @NotNull Editable s) {
int serialIndex = 4;
int lotIndex = 5;
int quantityIndex = 6;
EditText serial = findViewById(serialIndex);
EditText lot = findViewById(lotIndex);
EditText quantity = findViewById(quantityIndex);
String txt = partNum.getText().toString().toUpperCase();
partNumber = txt;
Global.isSerialized = DatabaseManager.isSerialized(txt);
Global.isLot = DatabaseManager.isLot(txt);
//this is not working. The fields do not get disabled.
if (!Global.isSerialized && !Global.isLot) {
lot.setEnabled(false);
serial.setEnabled(false);
findViewById(id).setNextFocusDownId(quantityIndex);
}
if (txt.equals("")) {
serial.setError(null);
lot.setError(null);
if (!quantity.isEnabled()) {
quantity.setEnabled(true);
quantity.setText("");
}
}
//This is working. The lot number field gets disabled.
if (Global.isSerialized) {
lot.setEnabled(false);
snRequired = true;
serial.setError("Serial Number Required");
quantity.setText("1");
quantity.setEnabled(false);
findViewById(id).setNextFocusDownId(serialIndex);
} else {
snRequired = false;
serial.setError(null);
quantity.setText("");
quantity.setEnabled(true);
}
//this is also working. The serial number field gets disabled.
if (Global.isLot) {
lot.setEnabled(true);
lnRequired = true;
lot.setError("Lot Number Required");
serial.setEnabled(false);
quantity.setText("");
quantity.setEnabled(true);
findViewById(id).setNextFocusDownId(lotIndex);
} else {
lot.setError(null);
lnRequired = false;
}
Any ideas?