猿问
android中的DoubleTap
我需要创建一个小的文本区域。当我双击该文本区域时,它将移至下一个活动。我该怎么做?
慕斯709654
浏览 560
回答 3
3回答
海绵宝宝撒
更好的选择是创建一个轻量级的Abstract类public abstract class DoubleClickListener implements OnClickListener { private static final long DOUBLE_CLICK_TIME_DELTA = 300;//milliseconds long lastClickTime = 0; @Override public void onClick(View v) { long clickTime = System.currentTimeMillis(); if (clickTime - lastClickTime < DOUBLE_CLICK_TIME_DELTA){ onDoubleClick(v); lastClickTime = 0; } else { onSingleClick(v); } lastClickTime = clickTime; } public abstract void onSingleClick(View v); public abstract void onDoubleClick(View v);}并像这样使用 view.setOnClickListener(new DoubleClickListener() { @Override public void onSingleClick(View v) { } @Override public void onDoubleClick(View v) { } });
0
0
0
ITMISS
下面的代码使用非常简单的逻辑 boolean firstTouch = false; @Override public boolean onTouchEvent(MotionEvent event) { if(event.getAction() == event.ACTION_DOWN){ if(firstTouch && (Helper.getCurrentTimeInMilliSeconds() - time) <= 300) { //do stuff here for double tap Log.e("** DOUBLE TAP**"," second tap "); firstTouch = false; } else { firstTouch = true; time = Helper.getCurrentTimeInMilliSeconds(); Log.e("** SINGLE TAP**"," First Tap time "+time); return false; } } return true; }
0
0
0
随时随地看视频
慕课网APP
相关分类
Android
我要回答