gpt4 book ai didi

java - 如何在 Java 文件中设置全局变量

转载 作者:行者123 更新时间:2023-11-30 02:59:59 24 4
gpt4 key购买 nike

在lua中我可以只做全局变量名并bam它的全局变量java 有没有一种简单的方法可以做到这一点?

这是我的代码,我希望 loc 变量是全局变量,以便 public View getView(intposition, View ConvertView, ViewGroupparent){ 可以使用它:

class custom_row_adapter extends ArrayAdapter<Integer> {
custom_row_adapter(Context context, int picId, String url) {
super(context, R.layout.activity_custom_row_adapter, picId);
String loc = url;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater picInflater = LayoutInflater.from(getContext());
View customView = picInflater.inflate(R.layout.activity_custom_row_adapter, parent, false);
String singlePic = getItem(loc + String.valueOf(position) + ".jpg"); **//this is where loc is viewed**
ImageView theImage = (ImageView) customView.findViewById(R.id.singleImg);
Glide.with(this).load(singlePic).into(theImage);
return customView;
}

}

最佳答案

只需将其添加为这样的字段

public class example {

private String loc;

class custom_row_adapter extends ArrayAdapter<Integer> {
custom_row_adapter(Context context, int picId, String url) {
super(context, R.layout.activity_custom_row_adapter, picId);
loc = url;
}
}
}

关于java - 如何在 Java 文件中设置全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36237932/

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