0

I had a question on input while the Android Keyboard is up. I am running some validation (on the back end) and I need the capability to disable the keyboard after a single key is pressed. I don't want to remove the keyboard. I just want the capability to disable it while I verify then re-enable it. I cannot find out how to do this. Thank you.

New Guy
  • 496
  • 6
  • 24
  • possible duplicate: http://stackoverflow.com/questions/25216749/softkeyboard-open-and-close-listener-in-an-activity-in-android – David Jun 27 '16 at 11:56
  • @David unfortunately this is not a duplicate of that post, I want to keep views up just disable user input while the keyboard is up. The only solution I can think of is have the user type in something, then anything the user types after I automatically delete until I verify what they first typed in. For example someone types "cat", they first hit the "c" key I do verification, if its not done, if the user hits "a" I delete it until I verify the "c" input. – New Guy Jun 27 '16 at 15:06

1 Answers1

0

You can always use the input filters to sort this out:

In your onCreate():

editText = (EditText)findViewById(R.id.edittext);
setEditTextMaxLength(1);

if(verifiedAtBackend()) {
    editText.setFilters(new InputFilter[] {});
}

Create the method now, which would limit your input to 1 character:

private void setEditTextMaxLength(int length) {
    InputFilter[] FilterArray = new InputFilter[1];
    FilterArray[0] = new InputFilter.LengthFilter(length);
    editText.setFilters(FilterArray);
}

private boolean verifiedAtBackend() {
    //call your backend and see if the verification is true. If it is, return true and the filter would get removed.
}
Akeshwar Jha
  • 4,190
  • 5
  • 42
  • 85
  • I'd say that this is close to what I need. I do start with an initial value though which character amount can vary (1/2/3/4/5/6 digits). It does block input though after setting the filter which is nice. I might be able to create a custom eidt text which extends off of the android widget which then could utilize this. It would take some decent tweaking and have to use a lot of extra listeners. I would hope for an easier solution – New Guy Jun 28 '16 at 12:17
  • I should also mention that I need to verify the input before putting it on the screen. Which would be great if I didn't have to use "." or "," (period or comma) since key events are not triggered for these. – New Guy Jun 28 '16 at 13:10