12

I am trying to disable an EditText programmatically in Kotlin but I am not finding any method to do. I tried below code which didnt work:

panEditText.focusable = false //Requires API 26 and above.

panEditText.enabled = false //No such method found

How to disable EditText in Kotlin programming language?

4
  • By disable do you want deny userInput or just hide it from the view? If you want to hide it will be panEditText.visibility=view.INVISIBLE Commented Mar 31, 2018 at 18:09
  • disable user from entering values @udit7395 Commented Mar 31, 2018 at 18:11
  • 1
    setEnabled is indeed inaccessible from kotlin, can't figure out why though Commented Mar 31, 2018 at 18:13
  • 1
    use isEnabled instead of enabled. Commented Mar 31, 2018 at 18:16

1 Answer 1

24

You should use isEnabled.

Set the enabled state of this view.

 panEditText.isEnabled =false

Method Overview

@android.view.RemotableViewMethod
    @Override
    public void setEnabled(boolean enabled) {
        if (enabled == isEnabled()) {
            return;
        }

        if (!enabled) {
            // Hide the soft input if the currently active TextView is disabled
            InputMethodManager imm = InputMethodManager.peekInstance();
            if (imm != null && imm.isActive(this)) {
                imm.hideSoftInputFromWindow(getWindowToken(), 0);
            }
        }

        super.setEnabled(enabled);

        if (enabled) {
            // Make sure IME is updated with current editor info.
            InputMethodManager imm = InputMethodManager.peekInstance();
            if (imm != null) imm.restartInput(this);
        }

        // Will change text color
        if (mEditor != null) {
            mEditor.invalidateTextDisplayList();
            mEditor.prepareCursorControllers();

            // start or stop the cursor blinking as appropriate
            mEditor.makeBlink();
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.