内部类调用外部类变量的问题
private void compressAndSend( File myfile , int position) {
Luban.get(getApplicationContext())
.load(myfile) //传人要压缩的图片
.putGear(Luban.THIRD_GEAR) //设定压缩档次,默认三挡
.setCompressListener(new OnCompressListener() { //设置回调
@Override
public void onStart() {
//TODO 压缩开始前调用,可以在方法内启动 loading UI
}
@Override
public void onSuccess(File file) {
//TODO 压缩成功后调用,返回压缩后的图片文件
OkHttpUtils
.post()
.url(UrlConstants.IMAGEUP)
.addFile("mFile", myfile.getName(),file)
.addParams("type", "dynamic")
.build()
.execute(new Callback() {
@Override
public String parseNetworkResponse(Response response, int id) throws Exception {
String string = response.body().string();
return string;
}
@Override
public void onError(Call call, Exception e, int id) {
}
@Override
public void onResponse(Object response, int id) {
Gson mGson = new Gson();
String gsonResponse = response.toString();
ImageBean ib = mGson.fromJson(gsonResponse, ImageBean.class);
if (ib.error == "0") {
photoPaths.set(position ,ib.name);
LogUtil.logi(myfile.getName() + "name " + position); //这里Log..
//这里要获取传入的参数position 和 myfile 去处理
++netPhotoCount;
} else {
ToastUtil.showToast(getApplicationContext(),"部分图片上传失败,请重新上传或检查网络");
}
}
});
}
@Override
public void onError(Throwable e) {
//TODO 当压缩过去出现问题时调用
}
}).launch();
}
但是使用的话就提示我要加final ... 我加final之后重复调用却会被覆盖... 重复调用9次传入不同的file和0~8 的position... Log却出现以下情况..
09-19 12:25:12.163 10155-10155/com.tongqu.myapplication : mmexport1474211278990.jpgname 8
09-19 12:25:12.227 10155-10155/com.tongqu.myapplication: mmexport1474211278990.jpgname 8
09-19 12:25:12.232 10155-10155/com.tongqu.myapplication: mmexport1474211278990.jpgname 8
09-19 12:25:12.234 10155-10155/com.tongqu.myapplication: mmexport1474211278990.jpgname 8
09-19 12:25:12.237 10155-10155/com.tongqu.myapplication: mmexport1474211278990.jpgname 8
09-19 12:25:12.250 10155-10155/com.tongqu.myapplication: mmexport1474211278990.jpgname 8
09-19 12:25:12.251 10155-10155/com.tongqu.myapplication: mmexport1474211278990.jpgname 8
09-19 12:25:12.253 10155-10155/com.tongqu.myapplication: mmexport1474211278990.jpgname 8
09-19 12:25:12.254 10155-10155/com.tongqu.myapplication: mmexport1474211278990.jpgname 8
也就是9次都得到了同样的对象... 是最后一个...
那么...
请问各位大大.. 我要怎样让内部类在调用多次的时候能正确获取到传进来的file和position呢...