-1

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 エラー: 別のメソッドで定義された内部クラス内の非最終変数を参照できません

(iを参照)

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 に答える