如何在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);
}
}); }
Eclipse错误:不能引用在不同方法中定义的内部类中的非final变量
(指i)
答案 0 :(得分: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);
}