0

Many questions refer to a keyboard service rearing it's head at the wrong time, or how to substitute a view specific keyboard. I have no problem doing this. This problem is different in that the keyboard service pops up on top of a custom keyboard that was working fine until a long press to make a selection. At that point the default keyboard appears. I want to stop this.

As further clarification, it is not the long press that opens the system keyboard. It is action of making a selection. For example: A long press at the end of input does not select anything, but does pop up the "cut copy select all share..." dialog. When you click on "Select All" then the system keyboard opens.

I think the misleading suggestion of a link to a solution to this problem should be removed.

I use the following to install a special keyboard under an EditText:

        MA_expression.setOnClickListener { view ->
        mKeyboardView.visibility = View.VISIBLE
        mKeyboardView.isEnabled = true
        if (view != null) {
            val imm = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
            imm.hideSoftInputFromWindow(view.windowToken, 0)
        }

    }

This works as expected:

Use clicks in EditText

Now the goal is to use "45" as the argument to a function, so the range of text that is to become the argument is selected (simple here, but it could just as well be embedded in a more complicated expression):

Text is selected by long press

Now the problem is evident -- the standard keyboard service has popped up. It can be dismissed with the done button, the selection remains, my keyboard remains, the FUNa keyboard is selected and the function to apply is picked.

System keyboard is displayed by the mechanism to create a selecdtion

enter image description here

The result is correct, it is only the intervening system keyboard that must be told it is not wanted.

How is that done?

2
  • This question will help you: stackoverflow.com/a/17789187/4402638 Commented Jul 24, 2018 at 15:51
  • Neither of above suggestions address this question. The question was edited to clarify that the problem is only apparent if a long press is used to open the selection popup. Commented Jul 25, 2018 at 23:18

1 Answer 1

0

dismiss the android key board on the focus listener view.setOnFocusChangeListener

view.setOnFocusChangeListener(new OnFocusChangeListener() {
    @Override
    public void onFocusChange(View view, boolean hasFocus) {
        if (hasFocus) {
            val imm = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
            imm.hideSoftInputFromWindow(view.windowToken, 0)
        }
    }
});
Sign up to request clarification or add additional context in comments.

3 Comments

This does not work. A long press in an EditText that already has focus (with no soft input because it was turned off in onCreate) does not even receive an onFocusChange callback.
how about not disabling it in onCreate?
Sorry, I meant to say in an onClickListener. The onFocusChangeListener by itself is less useful -- the system keyboard is always displayed when the user clicks in the EditText.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.