0

I have an activity which creates a fragment with VerticalGridView. In activity I have this:

@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
    if (fragment != null) {
        if (fragment.handleKeyDown(keyCode)) {
            return true;
        }

        // todo swallow some events
    }
    return super.onKeyDown(keyCode, event);
}

Since I need to do some special treatment for UP, DOWN, LEFT and RIGHT so I override this onKeyDown.

Then I have a custom viewHolder GridItemViewHolder extends RecyclerView.ViewHolder, in this viewHolder I have:

    gridItemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LOG.d("onclick!!");
            }
        });

But this onclick method is never called when I press "Enter". Am I missing something here? Is onKeyDown override the onClick?

Thanks!!

Zip
  • 809
  • 2
  • 14
  • 30

1 Answers1

0

Use OnItemClickListener for GridView

gridItemView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                                int i, long id) {
        LOG.d("onclick!!"+i);

} });

sangavi
  • 441
  • 1
  • 3
  • 13
  • I tried this too, still not working. So I put logs in onKeyDown and it showed up for enter key which I think this method might override the onclick. – Zip Jan 25 '17 at 08:35
  • Can you post your coding? is there any error shown in log cat did you check it with Toast. – sangavi Jan 25 '17 at 08:53
  • My viewholder looks exactly like this answer: http://stackoverflow.com/a/32780492 . And I figured that `onKeyDown` is not overriding the `onClick`, I removed `onKeyDown`, still not working. – Zip Jan 25 '17 at 18:40
  • where did you use OnItemClickListener? are you using in Activity? – sangavi Jan 27 '17 at 04:34
  • use the above answer in your activity – sangavi Feb 04 '17 at 04:31