hi Guillaume
    Thanks for your response. I tried to override the
onCreateContextMenu directly in MapActivity. The result is the same as
the above. Below is the source code.
package android.demo;
import com.google.android.maps.MapActivity;
import android.os.Bundle;
import com.google.android.maps.MapView;
import android.view.ContextMenu;
import android.view.KeyEvent;
import android.view.View;
import android.util.*;
public class demo extends MapActivity {
    /** Called when the activity is first created. */
        MapView mapView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mapView = (MapView) findViewById(R.id.mapview1);
        // We also want to show context menu for longpressed items in
the gallery
      //init the map view
        registerForContextMenu(mapView);

    }
    public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenu.ContextMenuInfo menuInfo) {
                  menu.setHeaderTitle("Menu");
              menu.add(0, 1, 0, "Add");
              menu.add(0, 2, 0, "Delete");
              menu.add(0, 3, 0, "Edit");
           }
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_Z) {
                mapView.getController().zoomIn();
                return true;
        } else if (keyCode == KeyEvent.KEYCODE_X) {
                mapView.getController().zoomOut();
                return true;
        }

        return super.onKeyDown(keyCode, event);
}

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
}





On 12月26日, 下午8时14分, Guillaume Perrot <[email protected]> wrote:
> Why don't you override the onCreateContextMenu directly in
> MapActivity ?
>
> On Dec 26, 10:15 am, "[email protected]" <[email protected]>
> wrote:
>
>
>
> > hi all
> >     I want to create a context menu when LongClick is hitted. As
> > result mapview is opened successfully; but the LongClick got no
> > response. Would you like to give me a hand how to solve it? Below is
> > the complete code. Thank you very much.
>
> > package android.demo;
> > import com.google.android.maps.MapActivity;
> > import android.os.Bundle;
> > import com.google.android.maps.MapView;
> > import android.view.ContextMenu;
> > import android.view.View;
> > import android.util.*;
> > public class demo extends MapActivity {
> >     /** Called when the activity is first created. */
> >         MapView mapView;
> >     @Override
> >     public void onCreate(Bundle savedInstanceState) {
> >         super.onCreate(savedInstanceState);
> >         setContentView(R.layout.main);
> >         mapView = (MapView) findViewById(R.id.mapview1);
> >         // We also want to show context menu for longpressed items in
> > the gallery
> >       //init the map view
>
> >         mapView.setOnLongClickListener(new View.OnLongClickListener(){
>
> >         public boolean onLongClick(View v) {
> >         mapView.showContextMenu();
> >         return true;
> >         }
>
> >         });
>
> >         mapView.setOnCreateContextMenuListener(new
> > View.OnCreateContextMenuListener() {
> >         public void onCreateContextMenu(ContextMenu menu, View v,
> > ContextMenu.ContextMenuInfo menuInfo) {
> >                   menu.setHeaderTitle("Menu");
> >               menu.add(0, 1, 0, "Add");
> >               menu.add(0, 2, 0, "Delete");
> >               menu.add(0, 3, 0, "Edit");
> >            }
> >         });
>
> >         registerForContextMenu(mapView);
>
> >     }
>
> >     @Override
> >     protected boolean isRouteDisplayed() {
> >         // TODO Auto-generated method stub
> >         return false;
> >     }
>
> > }- 隐藏被引用文字 -
>
> - 显示引用的文字 -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to