why key events not executing when button is focused?

18 views Asked by At

I have a button focused in a view. Also I have a overridden method onKeyDown().

Now when button is clicked via remote, onClickListener gets invoked but why the onKeyDown() in not getting invoked.

1

There are 1 answers

0
Dipendra Sharma On

onKeyDown() and onKeyUp() both events are more specially for Hardware button. Although these events are complitable with soft button as well. These both events not supports focus change.

To get focus change event you can use OnFocusChangeListener() this will be best practice.

button.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            // TODO Auto-generated method stub
            if (hasFocus) {
                //Toast line...
            }
        }

    });