在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; }
}
只需将其添加为和字段,如
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;
}
}
}