gpt4 book ai didi

java - 在android中的Listener中获取值

转载 作者:行者123 更新时间:2023-12-01 06:40:51 24 4
gpt4 key购买 nike

我有一些这样的代码:

 final int height = 0; //I want to get this height after Predraw view
view.addOnPreDrawListener(new OnPreDrawListener()
{

@Override
public boolean onPreDraw()
{
int myHeight = itemLayout.getMeasuredHeight();
height = myHeight; //this line has error
return false;
}
});

问题是我如何从监听器获取值(尤其是原始类型)。总是显示

 Cannot refer to a non-final variable height inside an inner class defined in a different method 

然后我尝试将变量更改为final,它显示错误:

 The final local variable height cannot be assigned, since it is defined in an enclosing type

不知道为什么API很难用。

最佳答案

onCreate(....)之前将其声明为global int myHeight;

关于java - 在android中的Listener中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10597514/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com