1

So this is my problem, my code works fine and when i press space from my physical keyboard it does what it supposed to, but when i press space on soft keyboard, it doesn't work. I tried running my code with KEYCODE_ENTER and it is actually working fine on both hard and soft keyboard.

This is my code:

        editTextInput.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {

            if ((event.getAction() == KeyEvent.ACTION_UP) && (keyCode == KeyEvent.KEYCODE_SPACE)) {


                //If paragraph contains the word then it returns true, thus increasing wordCount by 1
                if(paragraphToArray(testParagraph,search) == true)
                {
                    wordCount += 1;
                }
                if(wordCount == 1)
                {
                    startTimer();
                }
                //Clearing the editTextInput edit area.
                editTextInput.setText("");

                //search = "";
                search.replace(0,30,"");

                return true;
            }
            return false;
        }
    });
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Possible duplicate of [DispatchKeyEvent to listen for Spacebar being pressed](https://stackoverflow.com/questions/23618567/dispatchkeyevent-to-listen-for-spacebar-being-pressed) – Baris Akar Jun 06 '18 at 13:54

0 Answers0