Search code examples
google-tv

ItemClickListener kicking off while ItemLongClickListener happens


The best way I can describe this is the following. I have a poster gallery that has a bunch of images. The selected poster gets highlighted as the user moves back and forth through the gallery. I have the following code set on the poster gallery:

 Gallery posterGallery = (Gallery) context.findViewById(R.id.moviePosterGallery);
 posterGallery.setAdapter(new MoviePosterImageGalleryAdapter(context, key,
                          item.getCategory()));
 posterGallery.setOnItemSelectedListener(
    new MoviePosterOnItemSelectedListener(bgLayout, context));
 posterGallery.setOnItemClickListener(new MoviePosterOnItemClickListener());
 posterGallery.setOnItemLongClickListener(new MoviePosterOnItemLongClickListener());

What seems to happen is if you press the Remote on the vizio costar, both the Click and Long click events are being fired if you hold down the OK button. As in my case a dialog pops up when a Long click is received, but also the poster launches the video related to that to start playing which is part of the ItemClickListener code..

When testing the same code on a Nexus 7 tablet, only the long click is fired, not both. Is there a way to handle the long click correctly on Google TV. I'm using a vizio costar with Google TV 3 if that helps.

Also, if you move the mouse pointer over the item, and then hold down the - key on the front of the remote, only the long click event is triggered. It just seems to be related to the OK and how long that held down.

I looked at the following similar issue:

onListItemClick and onItemLongClick Google TV

but I already have the onItemLongClick returning true when it handles the event.


Solution

  • There is a quirk with the Vizio remotes. The OK button is not mapped to the right keycode. The Vizio remote sends KEYCODE_ENTER when OK is pressed when in fact it should be sending KEYCODE_DPAD_CENTER. This is what is causing your issue I think. If you try using AbleRemote as the input device you should be able to see it working as expected. Now to solve your issue you may have to go to a keycode listener if a keyboard is present and detect the key events on the posterGallery to fire off short and long clicks.