W.K.S
W.K.S

Reputation: 10095

How to disable typing into EditText once its visibilty is set to Gone

I am writing an application on Android and I have these bunch of buttons; when you click on them the input panel (EditText) appears if it is not already visible otherwise it disappears. The problem is that the user can still type into the EditText even after it's disappeared. I've attached two pictures to show what I mean.

User can type when Edit Text is visible User can type when EditText is gone (I can still type)

I tried .setEnabled(false) - didn't work.

I tried .setFocusable(false) - didn't work.

I tried both together - didn't work.

Upvotes: 0

Views: 1692

Answers (4)

you can use TextWatcher alongwith flag http://developer.android.com/reference/android/text/TextWatcher.html

prepare logic such that once visibilty gone then in public void onTextChanged(CharSequence s, int start, int before, int count) put same Text as earlier

refer this too Android TextWatcher.afterTextChanged vs TextWatcher.onTextChanged

Upvotes: 1

Dante
Dante

Reputation: 1094

These answers to these questions say you can use an InputFilter

editText.setFilters(new InputFilter[] {
    new InputFilter() {
        public CharSequence filter(CharSequence src, int start,
            int end, Spanned dst, int dstart, int dend) {
            return src.length() < 1 ? dst.subSequence(dstart, dend) : "";
        }
    }
});

Why can I type into a disabled EditText?

Can we have uneditable text in edittext

Upvotes: 0

Belurd
Belurd

Reputation: 782

I think you need to close Android soft keyboard. This link will help you with this issue: Close/hide the Android Soft Keyboard

Upvotes: 1

Jin35
Jin35

Reputation: 8612

You can try hide soft keyboard before setting visibility.

InputMethodManager imm = (InputMethodManager) YourActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editView.getWindowToken(), 0);

Upvotes: 1

Related Questions