如果触摸标记3秒钟,该怎么做

时间:2013-02-25 15:27:15

标签: android timer android-mapview

我有一个带谷歌地图api v2的应用程序,上面有一些标记。对于每个标记,如果我点击它,它会打开一个气球,上面有一些关于它的标题等。 使用SystemClock,它只等待3秒,但它会执行操作。

如果用户在该标记上按下X秒,我想做点什么吗?我尝试使用线程但我没有设法做到这一点。

if (onBalloonTap(currentFocusedIndex, currentFocusedItem)) {
            long thisTime = 0;
            thisTime = SystemClock.uptimeMillis();
            if (thisTime > 3000) {

                DirectionsTask getDirectionsTask = new DirectionsTask();
                getDirectionsTask.execute(getCurrentLocation(),
                        currentFocusedItem.getPoint());
            }

1 个答案:

答案 0 :(得分:0)

类似的东西?

    GeoPoint p = null, currentP = null;
    boolean isActivated = false;
    view.setOnTouchListener(new OnTouchListener() { 
        public boolean onTouch(View v, MotionEvent event) { 
            if(event.getAction()==MotionEvent.ACTION_DOWN) {
                isActivated = false;
                currentP = p ;
            }
            if(currentP == p && event.getEventTime()-event.getDownTime()>3000 && !) { 
                Toast.makeText(AudioPlayerActivity.this, "3 sec", Toast.LENGTH_LONG).show(); 
                isActivated = true; //avoid displaying a lot of toast } return true; } });
            }
            if(event.getAction()==MotionEvent.ACTION_UP) {
                currentP = null; p = null;
            }
        }
    });

     //extends Overlay type, works if the method is called when "action down"
     public boolean onTap(GeoPoint p, MapView    mapView)  {
          this.p = p;
          return true;
     }