-1

我如何在动画监听器中使用变量

前任。

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);
}

}); }

Eclipse 错误:无法引用以不同方法定义的内部类中的非最终变量

(指我)

4

1 回答 1

0

做这个

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);
}
于 2012-06-24T18:51:47.173 回答