0
我想创建一个“正在搜索”文本,其格式如下: “正在载入”。 - >“正在加载..” - >“正在加载...”未来任务无法正常工作(Android)
然后,一旦我得到某些数据,停止此动画文本,只需将文本设置为“找到”。
我试图实现这种方式:
ExecutorService threadPoolExecutor = Executors.newSingleThreadExecutor();
Future textAnimationTaskFuture;
Runnable textAnimationTask;
textAnimationTask = new Runnable() {
@Override
public void run() {
int passedTime = 0;
while(passedTime < 3000)
{
if(passedTime < 1000){
textView.setText("Loading.");
}
else if(passedTime >= 1000 && passedTime < 2000)
{
textView.setText("Loading..");
}else if (passedTime >= 3000)
{
textView.setText("Loading...");
}
passedTime = passedTime + 1;
if(passedTime == 3000)
passedTime = 0;
}
}
};
然后,我会跑的过程:
textAnimationTaskFuture = threadPoolExecutor.submit(textAnimationTask);
,并取消它:
textAnimationTaskFuture.cancel(true);
textView.setText("Found.);
不幸的是,循环不停止取消(真)。
尝试调试它,不幸似乎无法找到问题..也许我做错了什么..:/ – BVtp
嗯......看看这里,也许这会帮助你:http://stackoverflow.com /问题/ 13623445 /未来取消法 - 是 - 不工作 – yakobom