Contextual Menu on a MapView

Tutorials that use the MapActivity. Many using GPS functionality.

Contextual Menu on a MapView

Postby chris » Thu May 15, 2008 10:22 pm

Hi

Don't know if this will help anyone , but here is a little trick i found to use contextual menu on a map view.
Just extend the CustomMapView , use the onlongPress to display the contextual menu instead of the zoom dialog.
use this wiew in xml :

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <view class="com.piggyBack.uii.CustomMapView"
  2.  
  3.                         android:id="@+id/map" android:layout_width="fill_parent"
  4.  
  5.                         android:layout_height="wrap_content" />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4



Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. public class CustomMapView extends MapView {
  5.  
  6.         public static final String TAG="CustomMapView";
  7.  
  8.         public CustomMapView(Context context, AttributeSet attrs, Map inflateParams) {
  9.  
  10.                 super(context, attrs, inflateParams);
  11.  
  12.                 // TODO Auto-generated constructor stub
  13.  
  14.         }
  15.  
  16.  
  17.  
  18.         public CustomMapView(Context context) {
  19.  
  20.                 super(context);
  21.  
  22.                 // TODO Auto-generated constructor stub
  23.  
  24.         }
  25.  
  26.  
  27.  
  28.         /* (non-Javadoc)
  29.  
  30.          * @see com.google.android.maps.MapView#onLongPress(float, float)
  31.  
  32.          */
  33.  
  34.         @Override
  35.  
  36.         public boolean onLongPress(float x, float y) {
  37.  
  38.                    getParent().showContextMenuForChild(this);
  39.  
  40.                    return true;
  41.  
  42.         }
  43.  
  44.         /* (non-Javadoc)
  45.  
  46.          * @see android.view.View#onFinishInflate()
  47.  
  48.          */
  49.  
  50.         @Override
  51.  
  52.         protected void onFinishInflate() {
  53.  
  54.                 // TODO Auto-generated method stub
  55.  
  56.                 super.onFinishInflate();
  57.  
  58.                 setFocusableInTouchMode(true);
  59.  
  60.  
  61.  
  62.         }
  63.  
  64. }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
chris
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sat Feb 02, 2008 4:39 pm

Top

Return to Map Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests