【Android】双击事件


class onDoubleClick implements View.OnTouchListener{  
		 
		 int position;
                 //通过构造将数据传递过来
                onDoubleClick(int position){
			 this.position=position;
		 }
		 int count = 0;   
		 int firClick = 0;   
		 int secClick = 0;   
		     @Override    
		     public boolean onTouch(View v, MotionEvent event) {     
		         if(MotionEvent.ACTION_DOWN == event.getAction()){     
		             count++;     
		             if(count == 1){     
		                 firClick = (int) System.currentTimeMillis();     
		                      
		             } else if (count == 2){     
		                 secClick = (int) System.currentTimeMillis();     
		                 if(secClick - firClick < 1000){     
		                        //双击事件   
		                	 Log.e("TAG","双击事件===="+position);
		                 }     
		                 count = 0;     
		                 firClick = 0;     
		                 secClick = 0;     
		             }     
		         }     
		         return true;     
		     }     
		 }    




使用方法

         

       item.setOnTouchListener(new onDoubleClick(position));


你可能感兴趣的:(【Android】双击事件)