Question

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.

Was it helpful?

Solution

You can try hide soft keyboard before setting visibility.

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

OTHER TIPS

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

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top