Akh
Akh

Reputation: 6043

Disable DONE in soft keyboard until minimum number of characters are typed in edit text

I need to keep the DONE button (imeOptions-->IME_ACTION_DONE) on android's system softboard disabled until the minimum number of characters are entered in the edit text. Any suggestions?

Note: Minimum number of characters is just one such validation that needs to be performed on the edittext user input. So until the user entered text pass through all the validations the DONE needs to be kept disabled preventing user from navigating to the next step.

Thanks

Upvotes: 2

Views: 2021

Answers (2)

Akh
Akh

Reputation: 6043

This is the closest I could get to. I couldn't disable the button but quietly consume the event triggered by the DONE button and do nothing.

        if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)){

        if(isValid(mTextView.getText()){
            //Permit further operation 
        }else{
            //Do nothing - This will consume the KEYCODE_ENTER action
        }
        return false;  //To let other listeners that this event has already been consumed
    }

Upvotes: 2

j__m
j__m

Reputation: 9645

My suggestion would be not to go down this path. Ultimately you have no control over what a soft keyboard does. Even if you found a method for doing this on the stock keyboard, it would likely not work with the Samsung Keyboard or the Swype Keyboard. Some third-party keyboards even ignore basic controls like inputType, happily showing letters to users for entry into numeric fields. You should treat all keyboard-related api's as advisory and not count on any of them being enforced.

Upvotes: 0

Related Questions