I have a textview and I have many buttons. One of the button should be able to start the 'animation' well it is not animation in anim, it just need to make the text go red for a 2 seconds than the text should go green for 2 seconds than again back to red.... -one of the buttons should stop the 'animation' and set the text to white -one should make the text back for 1 sec, than blue for 2sec and again back to black...
the point is the buttons should be able to be pressed by the user in any time.
I think I should use Handler but I am not sure for the patter , I do not know how the stoping of the thread should look like, I mean when I start thread , later on I should tell him to stop... What is the best way to do this ?
I always code this kind of thinks with stupid tricks , and I do not know what is the pattern, what is the right way to do this ?
Thanks
here is some code of how I do it, but I feel that this is not the right way
private boolean flagForStop=true;
private Handler handler1=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 0:
flagForStop=false;
case 1:
flagForStop=true;
break;
case 2:
new Thread(){
public void run(){
while(true){
if(flagForStop)break;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//do something
}
}
}.start();
break;
default:
break;
}
}
};
and than i the listener something like handler1.sendEmptyMessage(0);