Note that there are some explanatory texts on larger screens.

plurals
  1. POOnTouch in MapView only fires the first time
    text
    copied!<p>I'm trying to implement a double-tap zoom like function in my MapView. The event always fires the first time, but never subsequent times. Below is my code. I have a feeling it has something to do with the map controller getting lost after the first time the event is fired.</p> <pre><code>import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController; import com.google.android.maps.MapView; public class mainmap extends MapActivity implements OnTouchListener{ long lasttime = -1; MapController mapc; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); MapView mapView = (MapView) findViewById(R.id.mapview); mapView.setBuiltInZoomControls(true); mapc = mapView.getController(); mapView.setOnTouchListener(this); } @Override protected boolean isRouteDisplayed() { // TODO Auto-generated method stub return false; } @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN){ if(event.getEventTime()-lasttime&lt;2000){ mapc.zoomInFixing((int)event.getX(),(int)event.getY()); } } lasttime=event.getEventTime(); return true; } } </code></pre> <p>I have also tried editing the OnTouch method to cast the incoming View to a MapView, getting the controller while the event is fired. However, I get the same results where the first event is fired but not subsequent ones.</p> <pre><code>public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN){ if(event.getEventTime()-lasttime&lt;2000){ ((MapView)v).getController().zoomInFixing((int)event.getX(), (int)event.getY()); } } lasttime=event.getEventTime(); return true; } </code></pre> <p>Being as basic as possible, I cut out all of the code in the OnTouch method and programmed it to simply display a small toast message.</p> <pre><code>public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN){ Toast.makeText(this,"Down!",Toast.LENGTH_SHORT).show(); } return true; } </code></pre> <p>This works as expected, displaying the Toast each time the MapView is touched.</p> <p>I don't understand why the event will fire properly in this case but not in my previous implementation.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload