1

I am currently using TextInputEditText inside TextInputLayout. And wants to control editabilility programmatically. Make it editable on button click and uneditable clicking another button.

  deliveryQuantityTie.setFocusable(false);

set focus false make uneditable but set focus true does not make it editable. i also tried with toggling clickable,cursor visible , setkeylistener , nothing make it editable again.

what should i use to make it editable and uneditable in java code?

Bashir Fardoush
  • 184
  • 1
  • 10

3 Answers3

2

make your editText property setFocusable(true) and setEnabled(true) to true to make it editable it will solve your problem

Gowthaman M
  • 8,057
  • 8
  • 35
  • 54
Vikas Sharma
  • 685
  • 8
  • 18
1

Use setEnable(boolean)

How to disable?

TextInputEditText tie = findViewById(R.id.my_textInputEditText);
tie.setEnabled(false);

Result: Disabled

enter image description here

How to enable again?

tie.setEnabled(true);

Result: Enabled

enter image description here

Rohit Singh
  • 16,950
  • 7
  • 90
  • 88
0

You can make use of this

fragmentRegistrationFirstScreenBinding.etName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus){
                make editable and let user edit them
            }else {
                do not make editable
            }
        }
    });
Ankit Tale
  • 1,924
  • 4
  • 17
  • 30