Android的OnLongClickListener不是射击的MapView [英] Android OnLongClickListener not firing on MapView

查看:108
本文介绍了Android的OnLongClickListener不是射击的MapView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚注册在我的我的图形页面的OnLongClickListener上一个Android应用程序,我目前正在写。出于某种原因,但是onLongClick不会触发事件。

I just registered an OnLongClickListener on my my MapView on an Android app I'm currently writing. For some reason however the onLongClick event doesn't fire.

下面就是我写至今:

public class FriendMapActivity extends MapActivity implements OnLongClickListener {
    private static final int CENTER_MAP = Menu.FIRST;
    private MapView mapView;
    private MapController mapController;
    //...
    private boolean doCenterMap = true;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.friendmapview);
        this.mapView = (MapView) findViewById(R.id.map_view);
        this.mapController = mapView.getController();

        mapView.setBuiltInZoomControls(true);
        mapView.displayZoomControls(true);
        mapView.setLongClickable(true);
        mapView.setOnLongClickListener(new OnLongClickListener() {
            public boolean onLongClick(View v) {
                //NEVER FIRES!!
                return false;
            }
        });

        //...
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_3:
            mapController.zoomIn();
            break;
        case KeyEvent.KEYCODE_1:
            mapController.zoomOut();
            break;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        int actionType = ev.getAction();
        switch (actionType) {
        case MotionEvent.ACTION_MOVE:
            doCenterMap = false;
            break;
        }

        return super.dispatchTouchEvent(ev);
    }

        ...
}

五月覆盖这我加入的原因这个问题?有什么建议?

May overlays which I'm adding cause the problem?? Any suggestions?

推荐答案

在此同时,我发现了解决方案(或解决方法,把它作为你喜欢)我自己。我通过这个问题的工作方式是使用GestureDetector,并通过实现根据OnGestureListener接口转发所有的触摸事件到该对象。

In the mean time I found the "solution" (or workaround, call it as you like) by myself. The way I worked through this issue is by using a GestureDetector and forwarding all touch events to that object by implementing an according OnGestureListener interface.

我已经发布了一些code在我的博客如果有人有兴趣: http://juristr.com/blog/2009/12/图形页面 - 犯规 - 火onlongclick事件/

I've posted some code on my blog if anyone is interested: http://juristr.com/blog/2009/12/mapview-doesnt-fire-onlongclick-event/

不要问我为什么不直接在图形页面挂钩的OnLongClickListener工作。如果有人有一个解释,让我知道:)

Don't ask me why this didn't work by hooking up the OnLongClickListener directly on the MapView. If someone has an explanation let me know :)

更新:
使用GestureDetector带来一些弊端我的previously建议的解决方案。所以,我更新了博客文章在我的网站。

UPDATE:
My previously suggested solution using a GestureDetector posed some drawbacks. So I updated the blog post on my site.

这篇关于Android的OnLongClickListener不是射击的MapView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆