Reputation: 10095
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.
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
Reputation: 42016
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
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
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
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