我有isUnique()函数,内部函数有onResponse()方法 在onResponse内部,我将变量称为cancel,但是我不能
使用最终变量 final boolean cancel = true;
private boolean inUnique(final EditText data, String type) {
final boolean cancel = true; // the variable call in onResponse
Call<ResponseUnique> user=client.getApi().unique(data.getText().toString(), type);
user.enqueue(new Callback<ResponseUnique>() {
@Override
public void onResponse(Call<ResponseUnique> call, Response<ResponseUnique> response) {
if (!response.body().getStatus()){
View focusView = null;
data.setError(response.body().getMessage());
focusView = data;
focusView.requestFocus();
cancel = false; // the error
} else {
cancel = true; // error
}
}
@Override
public void onFailure(Call<ResponseUnique> call, Throwable t) {
View focusView = null;
data.setError("Tidak ada koneksi!");
focusView = data;
focusView.requestFocus();
cancel = false; // error
}
});
return cancel;
}
Java建议我将“取消”转换为最终元素数组