Question about the MapView double-click event in android?

Source: Internet
Author: User

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 );
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.