gpt4 book ai didi

Java Android :Add array 15times in one second How?

转载 作者:行者123 更新时间:2023-12-01 18:30:14 25 4
gpt4 key购买 nike

我想在一秒钟内添加数组 15 次。我使用过计时器、倒计时计时器、处理程序,但不适用于按钮 Action.Down 和 Action.Move。有什么帮助吗?

ArrayList<Integer> Xpos;
ArrayList<Integer> Ypos;
ArrayList<String> MarkerSelected;
private Handler handlerXYPos = new Handler();
Runnable runnableXYPos = null;



case MotionEvent.ACTION_DOWN:
handlerXYPos.post(runnableXYPos);
break;

case MotionEvent.ACTION_UP:
handlerXYPos.removeCallbacks(runnableXYPos);
break;


//=== case drag
case MotionEvent.ACTION_MOVE:
handlerXYPos.post(runnableXYPos);
break;

此可运行程序执行 15 帧

runnableXYPos = new Runnable() {  

@Override
public void run()
{

Xpos.add(xP);
Ypos.add(yP);
MarkerSelected.add(MarkerName);
handlerXYPos.postDelayed(runnableXYPos, 66); //convert 15 in milisec = 66


}
};

当我按下按钮时,此代码可以工作,有时会添加正确数量的值,但是当我拖动手指时,它会添加额外的值。

最佳答案

当您拖动时,会发生以下情况

1) MotionEvent.ACTION_DOWN called once when you press to start drag

2) MotionEvent.ACTION_MOVE is called several times depending on your drag

3) MotionEvent.ACTION_UP: will get called once when you release to finish drag

所以不需要在MotionEvent.ACTION_MOVE里面写代码

关于Java Android :Add array 15times in one second How?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24523032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com