Skip to content Skip to sidebar Skip to footer

How To Find Which Key Is Pressed In Android?

I would like to find out which key is pressed. I have a EditText and I added a KeyListener for it. but it doesnt seem to be working.I have a textview and I want to setText which is

Solution 1:

Try this. This one works on my project.

    editext.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if( (event.getAction() == KeyEvent.ACTION_DOWN) && 
                    (keyCode == KeyEvent.KEYCODE_DEL) ){
                Log.d(TAG, "Delete key clicked !");

                returntrue;
            }
            returnfalse;
        }
    });

If this doesn't work, you are probably listening a wrong EditText. Check your findViewById to see if your id is correct.

Post a Comment for "How To Find Which Key Is Pressed In Android?"