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