English 中文(简体)
页: 1
原标题:Android OnLongClickListener not firing on MapView

我刚刚在我的《地图评论》上登记了奥隆克·利维斯特,该文目前撰写。 然而,出于某种原因,LongClick事件造成大火。

这里,我刚才写道:

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

        ...
}

难道我还要花什么时间造成问题吗? 任何建议?

最佳回答

当时,我亲眼看到了“僵局”(或工作,称之为你)。 我通过这一问题开展工作的方式是利用一名地质构造者,通过实施“OnGestureListener”接口,把所有触动事件转交该物体。

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

不要问我,为什么通过直接在《地图集》上登上“OnLongClickListener”而这样做。 如果有人作解释,让我知道:

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

问题回答

我也遇到了同样的问题,对你的问题实际上有一个简单的解决办法;这是因为你重新使用错误的听众。

页: 1 OnMapLongClickListener( Object from the OnMapLongClickListener界面。

Hopefully everything should work properly :) Please tell me if it works.

我刚才谈到这个问题。 我曾尝试过上述解决办法,但是,尽管用户仍在玩弄inger,但是,它却在做100%的工作。

This is how I implemented a solution, using a handler and a delayed task - As a side note, I used a similar type implementation, but in reverse, to hide/show zoom controls on touch/etc..

private Handler mHandler = new Handler();

private final Runnable mTask = new Runnable() {
    @Override
    public void run() {
        // your code here
    }
};

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        // record the start time, start the timer
        mEventStartTime = ev.getEventTime();
        mHandler.postDelayed(mTask, LONG_PRESS_TIME);
    } else if (ev.getAction() == MotionEvent.ACTION_UP) {
        // record the end time, dont show if not long enough
        mEventEndTime = ev.getEventTime();
        if (mEventEndTime - mEventStartTime < LONG_PRESS_TIME) {
            mHandler.removeCallbacks(mTask);        
        }
    } else {
        // moving, panning, etc .. up to you whether you want to
        // count this as a long press - reset timing to start from now
                    mEventStartTime = ev.getEventTime();
        mHandler.removeCallbacks(mTask);
                    mHandler.postDelayed(mTask, LONG_PRESS_TIME);
    }

    return super.onTouchEvent(ev);
}

在《网上观察框架守则》中,LongClick(LongClick)用于处理长期的新闻活动,这就是Browser如何执行《安乐文》特征,因此LongClick没有发射。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签