0

I'm trying to enable and disable blinking animation on textview.

Start blinking works fine but stop blinking does usin:

anim.cancel();
anim.reset();

is not working and throws Null pointer exception. (But i dont know why, because variable is initialized).

How can i solve that please? Thanks for any advice.

Here is my code>

private Animation anim;


public void startBlinkText() {
        TextView myText = (TextView) findViewById(R.id.state);
        anim = new AlphaAnimation(0.0f, 1.0f);
        anim.setDuration(200); //You can manage the time of the blink with this parameter
        anim.setStartOffset(20);
        anim.setRepeatMode(Animation.REVERSE);
        anim.setRepeatCount(Animation.INFINITE);
        myText.startAnimation(anim);
    }

    public void stopBlinkText() {
        try {
            // TextView myText = (TextView) findViewById(R.id.state);
            anim.cancel();
            anim.reset();
            // myText.startAnimation(anim);
        } catch (Exception e) {
            Log.e(AppHelper.APP_LOG_NAMESPACE,
                    "stopBlinkText method cannot be processed", e);
            e.printStackTrace();
        }
    }
Blackbelt
  • 148,780
  • 26
  • 271
  • 285
redrom
  • 10,590
  • 29
  • 143
  • 244

1 Answers1

2

Use clearAnimation() to stop an animation. There is no loadAnimation()or clear() on View

Andriya
  • 242
  • 2
  • 13