在卢阿,我可以做global variablename
并将其全球化
在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 :(得分:2)
只需将其添加为和此字段
即可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;
}
}
}