2012-06-24 4 views
-1

Comment puis-je utiliser une variable dans un gestionnaire d'animationUtiliser la variable dans Animationlistener

for(int i = 0; i<ids.length; i++) { 

    //Doing some animation stuff based on 
    //imageView = (ImageView) findViewById(ids[i]); 




//I want to play a sound on the specific views animationstart   
    scalePause.addListener(new AnimatorListenerAdapter() { 
    public void onAnimationStart(Animator animation) { 
    sounds.play(letterSounds[i], 1.0f, 1.0f, 0, 0, 1.0f); 
} 

}); }

erreur Eclipse: ne peut pas se référer à une variable non finale dans une classe interne définie dans une autre méthode

(se référant à i)

Répondre

0

Est-ce que cette

for(int i = 0; i<ids.length; i++) { 
    ... 
    ... 
    //I want to play a sound on the specific views animationstart 
    final int index = i;  // assign to a final variable and use it.  
    scalePause.addListener(new AnimatorListenerAdapter() { 
    public void onAnimationStart(Animator animation) { 
    sounds.play(letterSounds[index ], 1.0f, 1.0f, 0, 0, 1.0f); 
} 
Questions connexes