如何从 Java 中的内部方法类访问变量?

问题描述

我有一个对象 mPhotoView,它在类(外部类?)CrimeFragment 中声明和定义。我想访问在 mPhotoView 的方法中定义的变量。

mPhotoView = (ImageView)v.findViewById(R.id.crime_photo);
    mPhotoView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            int thumbnailHeight = mPhotoView.getHeight();
            int thumbnailWidth =  mPhotoView.getWidth();
        }
    });
    updatePhotoView(thumbnailHeight,thumbnailWidth); // shows error here. 

我如何实现这一目标?

(我尝试将变量声明为 static/final 并尝试随机使用 this/super。我不太清楚基础知识。)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)