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?

Mike Hanafey
  • 5,276
  • 3
  • 15
  • 25
  • This question will help you: https://stackoverflow.com/a/17789187/4402638 – Óscar Jul 24 '18 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. – Mike Hanafey Jul 25 '18 at 23:18

1 Answers1

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)
        }
    }
});
Muhammad Naderi
  • 2,450
  • 2
  • 20
  • 32
  • 1
    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. – Mike Hanafey Jul 25 '18 at 14:29
  • how about not disabling it in onCreate? – Muhammad Naderi Jul 26 '18 at 18:01
  • 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. – Mike Hanafey Jul 27 '18 at 15:08