Robby Smet
Robby Smet

Reputation: 4661

Avoid edittext getting focus when text changes

I have a numberpicker with a plus and minus button and a edittext.

The user can click on the plus and minus button to increase / decrease or manually input when he clicks on the edittext.

But each time the user clicks a +/- button the text changes and the edittext receives focus. This means the border changes color and the cursor shows up.

I want to avoid that, how can I do this?

I tried adding clearFocus() to the onTextChanged listener, and this works but the border still changes color for a moment.

Upvotes: 0

Views: 179

Answers (1)

Milos Cuculovic
Milos Cuculovic

Reputation: 20223

In your XML file where you have your editText, you can set the focusable to false:

 android:focusable="false"

To show the keyboard manually, use:

InputMethodManager inputManager = (InputMethodManager)
            getSystemService(Context.INPUT_METHOD_SERVICE); 
    try{
    inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
               InputMethodManager.SHOW_FORCED);
    }
    catch (Exception e)
    {}

And put this on a listener.

Upvotes: 1

Related Questions