Question

)

I have an EditText on which I start a background animation, like this (Android):

EditText1.setBackgroundResource(R.drawable.blinker);
EditText1.getBackground().start();

Now I have an ArrayList with lets say 10 EditTexts. Next I say: Let the first 4 blinking. So I start my animation like above in a loop or method or whatever.

Next I wanna stop these animations with a method like allAnimationsStop(). So each animation which is running should stop. I could use a loop which execute stop() for every EditText.

The problem is e.g. EditText5 didn't get an animation as a background because I set it just for the first 4. So at this point I get an error.

My question is how can I check that on a EditText an animation or just picture is applied?

Thank you:-)

Was it helpful?

Solution

You need to check if the added background is an animation or not.

if(EditText1.getBackground() instanceof Animation){
    //call start or stop
}else{
    //leave it. this is not an animation
}

Or as a dirty solution, you can simply call the stop() method in a try...catch block and ignore the exception.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top