有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

如何使变量在Java文件中成为全局变量

在lua,我可以做global variablename,然后bam它的全局 在java中有没有一种简单的方法可以做到这一点

这是我的代码,我希望loc变量是全局变量,以便public View getView(int position, View convertView, ViewGroup parent){可以使用它:

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;
}

}


共 (0) 个答案