android 处理双击事件


  //监听 控件的双击事件
  // 计算点击的次数
  private int count = 0;
  // 第一次点击的时间 long型
  private long firstClick = 0;
  // 最后一次点击的时间
  private long lastClick = 0;
     public class TouchEvent implements OnTouchListener { 
   // TODO Auto-generated method stub
   @Override
   public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub
    
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
     // 如果第二次点击 距离第一次点击时间过长 那么将第二次点击看为第一次点击
     if(firstClick != 0 && System.currentTimeMillis() - firstClick > 500){
      count = 0;
      
     }
     count++;
     if(count == 1){
      firstClick = System.currentTimeMillis();

      System.out.println("LButton click--------------");
     }
     else if(count == 2){
      lastClick = System.currentTimeMillis();
      // 两次点击小于500ms 也就是连续点击
      if (lastClick - firstClick < 500){
       //Log.v("Double", "Double");
       System.out.println("Double click--------------");
      }
      clear();
     }
    }
    if (event.getAction() == MotionEvent.ACTION_UP) {
    }

    return false;
   }
   
   // 清空状态
   private void clear(){
    count = 0;
    firstClick = 0;
    lastClick = 0;
   }
  } 
    

http://www.cnblogs.com/myittec/archive/2011/09/19/2392853.html

 

http://jasonshieh.iteye.com/blog/751068

http://hi.baidu.com/duizhe_memory/item/9adbaa9b071431d67a7f01c8

你可能感兴趣的:(android 处理双击事件)