I want to make a 'seeking' text which will be like: "Loading ." -> "Loading .."-> "Loading ..."
and then once I get certain data , stop this animation text and just set the text as "Found."
I tried implementing it that way :
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;
}
}
};
And then I would run the process :
textAnimationTaskFuture = threadPoolExecutor.submit(textAnimationTask);
And cancel it :
textAnimationTaskFuture.cancel(true);
textView.setText("Found.);
Unfortunately the loop doesn't stop on cancel(true).