I have this function to show an AlertDialog when taping on marker:
protected boolean onTap(int index) {
db = openHelper.getWritableDatabase();
AlertDialog.Builder dialog = new AlertDialog.Builder(Geo.this);
String[] columns_descri = new String[] {COL_DESCRI};
Cursor cur = db.query(true, TABLE_COORD, columns_descri,null, null, null, null, null, null);
if (cur.moveToPosition(index-1)) {
String description = cur.getString(cur.getColumnIndexOrThrow(COL_DESCRI));
dialog.setTitle("Info.");
dialog.setMessage(description);
dialog.show();
}
db.close();
return true; }
And this method to retrieve any tapped touch on map:
@Override
public boolean onTouchEvent(MotionEvent event, MapView maMap)
{
//---when user lifts his finger---
if (event.getAction() == 1) {
GeoPoint p = maMap.getProjection().fromPixels(
(int) event.getX(),
(int) event.getY());
Toast.makeText(getBaseContext(),
p.getLatitudeE6() / 1E6 + "," +
p.getLongitudeE6() /1E6 ,
Toast.LENGTH_SHORT).show();
}
return true;
}
The problem is when onTouchEvent returns TRUE i can’t control the map, move it, or show the AlertDialog when taping on a marker. When it’s false, i re-take control of the map, but the toast displays many time(5 or 6 times).
What could be the source of this weird problem?
OnTouchEvent is called on EACH touch event.
Press, drag (many events), release.
Therefore your toast is showing a lot.
return true only inside your if clause and return false otherwise.
That should solve it.