0

I tried to capture key event for android. Here is the source code i tried:

text.setOnKeyListener(new OnKeyListener() {

            @Override
            public boolean onKey(View view, int keyCode, KeyEvent event) {
                if(keyCode==KeyEvent.KEYCODE_A){
                    Toast.makeText(MainActivity.this, "A Pressed!!", Toast.LENGTH_LONG).show();
                }
                return false;
            }
        });

But it's doesn't work or show any error. How can i handle the key event for android keyboard?

Suraj Neupane
  • 489
  • 3
  • 21

2 Answers2

0

Software keyboards don't generate onKey events. Only hardware keyboards do. If you want to see changes from a software keyboard, use a TextWatcher on the view.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
0

So you need to use TextChangedListener, Refer here, based on the text, do your work.

Community
  • 1
  • 1
Gunaseelan
  • 14,415
  • 11
  • 80
  • 128