我正在学习 android 并知道基本的编辑等。我有一个由一位自由职业者开发的应用程序。我们正在使用 Retrofit 2.0 在其中执行一些任务。我的功能之一如下所示
private void serverCall() {
progressDialog = new ProgressDialog(WithdrawActivity.this);
progressDialog.setMessage("Please wait...");
progressDialog.setCancelable(false);
progressDialog.show();
HashMap<String, String> payload = new HashMap<>();
String uid = settings.getString("userid", "");
payload.put("UID", uid);
payload.put("Name", etName.getText().toString().trim());
payload.put("MobileNumber", etPaytmMobileNumber.getText().toString().trim());
payload.put("Amount", etAmount.getText().toString().trim());
// NetworkApiInterface apiClient = NetworkApiClient.getClient().create(NetworkApiInterface.class);
NetworkApiInterface apiClient = retrofit.create(NetworkApiInterface.class);
Call<WithdrawalCreditResponseModel> call = apiClient.withdrawalCredit(payload);
call.enqueue(new Callback<WithdrawalCreditResponseModel>() {
@Override
public void onResponse(Call<WithdrawalCreditResponseModel> call, Response<WithdrawalCreditResponseModel> response) {
if (response != null) {
WithdrawalCreditResponseModel responseModel = response.body();
if (responseModel != null) {
Log.d(TAG, new Gson().toJson(responseModel));
if (!TextUtils.isEmpty(responseModel.getMsg())) {
Toast.makeText(WithdrawActivity.this, responseModel.getMsg(), Toast.LENGTH_SHORT).show();
}
if (responseModel.isSuccess()) {
setResult(RESULT_OK);
finish();
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
}
}
if (progressDialog != null) {
progressDialog.dismiss();
}
}
@Override
public void onFailure(Call<WithdrawalCreditResponseModel> call, Throwable t) {
t.printStackTrace();
Log.e(TAG, t.getCause() + "");
if (progressDialog != null) {
progressDialog.dismiss();
}
}
});
}
我想在调用成功时显示 toast 。我试过把它放在很多地方,但没有显示出来。我试着把它放在这一行之后等等
if (responseModel.isSuccess()) {
setResult(RESULT_OK);
Toast.makeText(WithdrawActivity.this, "This Toast Need toShow.", Toast.LENGTH_SHORT).show();
finish();
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
这是响应模型
public class WithdrawalCreditResponseModel implements Serializable {
@SerializedName("msg")
@Expose
private String msg;
@SerializedName("success")
@Expose
private boolean success;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
但它没有显示任何内容。但是,我的任务正在顺利完成。有人可以检查并告诉我其中有什么问题吗?
谢谢
最佳答案
确保你获得的成功是真实的并且它是 boolean 值,因为在你的模型类中你已经将成功作为 boolean 值
关于java - 改造成功电话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41866943/