I develop an application and I want to make a circle blink when you click on a button. I have 8 circle on my view and I want them blinking separatly. I use this code :
public void blink(final View id, final int position, final boolean bool) {
final Handler handler = new Handler();
Thread th = new Thread(new Runnable()
{
@Override
public void run() {
final int timeToBlink = 250;
try {
Thread.sleep(timeToBlink);
} catch (Exception e) {
e.printStackTrace();
}
handler.post(new Runnable()
{
@Override
public void run()
{
if (id.getVisibility() == View.VISIBLE) {
id.setVisibility(View.INVISIBLE);
} else {
id.setVisibility(View.VISIBLE);
}
blink(id,position,true);
}
});
}
});
th.setName(Integer.toString(position));
aThread.add(th);
th.start();
where id is the id of the circle
but I can't stop blink with th.interupt
anyone can help me please ?