在 android 如何在 AnimatorListener 的 onAnimationEnd() 方法中使用来自外部 class 的变量(而不使其成为最终变量)

In android How to use a variable(without making it final) from outer class in onAnimationEnd() method in AnimatorListener

我试图在另一个 ImageView 的平移动画结束时更改 ImageButton 的图像。我有一个用于动画的 AnimatorListener,并且想在 onAnimationEnd 方法中传递 ImageButton 值,以便我知道要更改哪个 ImageButton(在代码中进行一些计算来决定要更改哪个 Imagebutton)。我的代码如下。请帮帮我!!!

//animation of an imageview
ObjectAnimator move =ObjectAnimator.ofFloat(myAnimation1,"translationX",20);

//calculating which image to change to for the ImageButton
int id2 = this.getResources().getIdentifier("r" + a[m], "drawable", this.getBaseContext().getPackageName());

//adding animtor listener

move.addListener(new Animator.AnimatorListener(ImageButton,id2) {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        // TODO Auto-generated method stub

                        ImageButton.setImageResource(id2); //Not able to use ImageButton and id2...says it has to be final but I don't want it to be final

                        ImageButton.setClickable(true);

                    }});

再创建一个最终变量?

int id2 = this.getResources().getIdentifier("r" + a[m], "drawable", this.getBaseContext().getPackageName());

final int idFinal = id2;

//adding animtor listener

move.addListener(new Animator.AnimatorListener(ImageButton,id2) {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        // TODO Auto-generated method stub

                        ImageButton.setImageResource(idFinal); //Not able to use ImageButton and id2...says it has to be final but I don't want it to be final

                        ImageButton.setClickable(true);

                    }});