When I was working on a program, I encountered such a problem: Double-click mapView to respond to the event. Later I tried many methods and finally succeeded!
This is some information I have collected from the Internet. As follows:
Summary of properties and return values of touch and multiple mapviews
Serial number |
SetClickable |
SetEnabled |
OnTouch Function Return Value |
Result |
| 1 |
Default |
Default |
False |
Only responds for the first time. mapview responds normally. |
| 2 |
Default |
Default |
True |
The mapview fails to respond normally every time. |
| 3 |
True |
True |
False |
Only responds for the first time. mapview responds normally. |
| 4 |
True |
True |
True |
The mapview fails to respond normally every time. |
| |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
Draw a conclusion based on the above survey results
The returned values of the onTouch function directly affect the response of the onTouch function. The responses of mapview and onTouch functions are mutually exclusive and irrelevant to setClickable setEnabled.
I decided to use the dispatchTouchEvent function. below is the dispatchTouch method I have rewritten. The main function is to double-click mapView to automatically enlarge the map. For your reference!
First, this instance can only be used in version 4.0 or later.
You can only use dispatchTouchEvent instead of onTouchEvent because MapActivity inherits the dispatchTouch Event instead of OnTouchEvent"
@ Override
Public boolean dispatchTouchEvent (MotionEvent ev ){
Int actionType = ev. getAction ();
Switch (actionType ){
Case MotionEvent. ACTION_DOWN:
Count ++;
If (count = 1 ){
FirClick = System. currentTimeMillis ();
} Else if (count = 2 ){
// Toast. makeText (ActivityMain. this, "aaa", Toast. LENGTH_SHORT). show ();
SecClick = System. currentTimeMillis ();
System. out. println ("sec:" + secClick );
System. out. println ("first:" + firClick );
DistanceTime = secClick-firClick;
System. out. println ("distanceTime:" + distanceTime );
If (distanceTime> 1 & distanceTime <1000 ){
Toast. makeText (ActivityMain. this, "aaa", Toast. LENGTH_SHORT). show ();
IntZoomLevel ++;
If (intZoomLevel> mMapView01.getMaxZoomLevel ()){
IntZoomLevel = mMapView01.getMaxZoomLevel ();
}
MMapController01.setZoom (intZoomLevel );
}
FirClick = 0;
SecClick = 0;
Count = 0;
}
}
Return super. dispatchTouchEvent (ev );
}