我想連接/追加Retrofit2的onResponse回調內部的字符串中的字符串Android的改造2 - 不能通過onResponse回調
全局變量
Boolean isSaved = "false";
String message = "";
Queries queries = Server.getClient().create(Queries.class);
Call<ResponseModel> responseModelCall = queries.products(param1, param2);
responseModelCall.enqueue(new Callback<ResponseModel>() {
@Override
public void onResponse(Call<ResponseModel> call, Response<ResponseModel> response) {
if(response.isSuccessful()) {
if(response.body().getCode().equals("1")) {
message = "Success";
isSaved = true;
} else {
message = "Failed";
isSaved = false;
}
} else {
message = "Error";
}
}
@Override
public void onFailure(Call<ResponseModel> call, Throwable t) {
}
});
if(isSaved){
Toast.maketext(getActivity, "Congrats: "+message, LENGTH_SHORT).show();
} else {
Toast.maketext(getActivity, "I am sorry: "+message, LENGTH_SHORT).show();
}
如果數據保存那麼敬酒是 「恭喜:」
如果不是 「我很抱歉:」
我注意到字符串我過時了d從onResponse沒有工作。但布爾值確實起作用。
移動你的條件onResponse –