pehr.ans pehr.ans - 6 months ago 20
Android Question

Android: two event listeners - how to call both

Problem:

I have two listeners,

OnSingleTapListener
and
OnGraphicClick
<-ArcGIS-related listener. My problem is that one of my listeners intercepts user input over the other.

Goal:

Take a look at my attached screenshot; I'd like both listeners to be called when a user taps the "tap here" icons. Currently, when a user taps on the "tap here" icon -
OnGraphicClick
seems to intercept the user event and
OnSingleTapListener
is not called.

I tried to think of a way to call the
onSingleTap
method in
OnSingleTapListener
manually, but it requires
float
parameters (the screen position of where the user clicked) and
OnGraphicClick
takes an ArcGIS
graphic
object: the parameters for the two respective methods are not related.

Questions to Consider



  • Is there a way to mimic a user event by doing something similar to
    the
    performClick
    method that will perform a single tap
    at the location that the user tapped the "tap here" icon?

  • Could I perhaps make an invisible view placed atop the map view and place the
    OnSingleTapListener
    on that invisible view? If I did that would the user's tap events trickle down passed the invisible view to also interact with
    onGraphicClick
    listener placed on the map view?



Useful Info:

I'm working with the ArcGIS API for Android.

I have two listeners. One
OnSingleTapListener
that is set on a
MapView
object (main view with all the map stuff) and one ArcGIS-related
onGraphicClickListener
that is also set on the
MapView
object.

MySingleTapListener mySingleTapListener = new MySingleTapListener(mMapView.getContext(), mMapView);
mMapView.setOnSingleTapListener(mySingleTapListener);
mMapViewHelper = new EnhancedMapViewHelper(mMapView, handler, this); //<--onGraphicClickListener is set here


sample screen display

enter image description here

Answer

I wasn't able to get both listeners to work in tandem. However, I did find a solution.

The MapView class contains a toMapPoint method that converts screen coords to map coords. Here's how you can utilize this method:

  1. Simply set an OnSingleTapListener on the MapView being used.
  2. Have the onSingleTap method of the OnSingleTapListener convert every user event to map coords via the toMapPoint method.
  3. If the map coords are equivalent to the map coords of the "tap here" icons, then do something i.e. display a popup at those screen coords.