3
我的應用程序包含ViewFlipper
與一些圖像。當應用程序啓動時,ViewFlipper
startflipping()
。當用戶觸摸屏幕ViewFlipper stopflipping()
。我必須在上次觸摸60秒後執行此操作,ViewFlipper再次開始翻轉。我的類實現onTouchListener
,我有這個方法onTouch
:StartFlipping for ViewFlipper 60秒後從最後一次觸摸
public boolean onTouch(View arg0, MotionEvent arg1) {
switch (arg1.getAction()) {
case MotionEvent.ACTION_DOWN: {
downXValue = arg1.getX();
break;
}
case MotionEvent.ACTION_UP: {
currentX = arg1.getX();
if (downXValue < currentX) {
// Set the animation
vf.stopFlipping();
vf.setOutAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_right_out));
vf.setInAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_right_in));
// Flip!
vf.showPrevious();
}
if (downXValue > currentX) {
// Set the animation
vf.stopFlipping();
vf.setOutAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_left_out));
vf.setInAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_left_in));
// Flip!
vf.showNext();
}
if (downXValue == currentX) {
final int idImage = arg0.getId();
vf.stopFlipping();
System.out.println("id" + idImage);
System.out.println("last touch "+getTimeOfLastEvent());
}
break;
}
}
// if you return false, these actions will not be recorded
return true;
}
,我發現這個方法,尋找最後的接觸時間:
static long timeLastEvent=0;
public long getTimeOfLastEvent() {
long duration = System.currentTimeMillis() - timeLastEvent;
timeLastEvent = System.currentTimeMillis();
return duration;
}
我的問題是:我應該在哪裏叫getTimeOfLastEvent()
?如果我把它放在onTouch()
上,我將永遠趕不上getTimeOfLastEvent == 60000的那一刻,對吧?
作品...非常感謝:) – Gabrielle