I'm a beginner with the development of applications for Android and I just got a problem that I cannot solve.

I have a Rotation animation that loads from a layout and it works great, smooth and fast, but when I call an if statement with hasStarted() or hasEnded() nothing happens.

Here's the code:

public void onClick(View v) {
    // TODO Auto-generated method stub
    if(v==boton){
    int r;
    Random n = new Random();
    r=n.nextInt(ncategorias);
    Animation rotacion = AnimationUtils.loadAnimation(v.getContext(), R.anim.rotar);
    boton.startAnimation(rotacion);
    if(rotacion.hasEnded()) {
      categoria.setText(categorias[r]);
    }
    lista.PrimerNodo = lista.PrimerNodo.siguiente;
    hola=lista.PrimerNodo.datos.toString();
    vistajuego.setText(hola);
    }
}

Any help would be very useful! Thanks!

有帮助吗?

解决方案

That's because you're starting the animation and immediately checking if the animation has ended which is doubtful unless it simply doesn't do anything. What you want to do is implement an AnimationListener callback and set it to that animation, assuming you want to set that text immediately when the animation finishes.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top