android -> button double click

 

long space_last_click_time;
Button space_last_click_btn;
private void bindDoubleClickButton(final Button abcKey) {
	abcKey.setOnTouchListener(new View.OnTouchListener() {
		@Override
		public boolean onTouch(View v, MotionEvent event) {
			if (event.getAction() == MotionEvent.ACTION_DOWN) {
				print("touch down");
				if (abcKey == space_last_click_btn && (System.currentTimeMillis() - space_last_click_time) < 800) {
					// double click operation
					print("duble click");
					return true;//retur true will prevent the click event, false will continue to execute the click
				}
				space_last_click_time = System.currentTimeMillis();
				space_last_click_btn = abcKey;
			}
			return false;//retur true will prevent the click event, false will continue to execute the click
		}
	});

}

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326417498&siteId=291194637