-2

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 ?

Paul
  • 179
  • 1
  • 8
  • Add a boolean variable to block the recursive blink call in the thread. – jibysthomas Jul 17 '15 at 14:31
  • I test this but not work – Paul Jul 17 '15 at 14:32
  • 1
    Why cant you try with animation? when u done with blinking you can cleat the blink animation with clearAnimation(); Check this http://stackoverflow.com/questions/4852281/android-how-can-i-make-a-button-flash – jibysthomas Jul 17 '15 at 14:40
  • 1
    How many times do you want it to blink? You are just running a loop by calling it again within the Runnable so it will continue to blink nonstop. – Eugene H Jul 17 '15 at 14:41
  • @jibysthomas i will see this link thanks. i want it blink until that push a button to stop it – Paul Jul 17 '15 at 14:44
  • This surely help you i think http://stackoverflow.com/questions/3906738/android-blinking-image-using-the-alpha-fade-animation – jibysthomas Jul 17 '15 at 14:47
  • why my question vote down ?! – Paul Jul 17 '15 at 15:01

1 Answers1

1

Thank to @jibysthomas i fixe my problem i use this link and i made this :

final Animation animation = new AlphaAnimation(1, 0); 
        animation.setDuration(250); // duration - half a second
        animation.setInterpolator(new LinearInterpolator()); 
        animation.setRepeatCount(Animation.INFINITE); 
        animation.setRepeatMode(Animation.REVERSE);

and i call this annimation on my circle.

Thanks a lot to jibysthomas

Community
  • 1
  • 1
Paul
  • 179
  • 1
  • 8