Anisha Pandey
Anisha Pandey

Reputation: 85

Retrofit Success call

I am learning android and know basic editing etc. I have one application which have developed by one freelancer. We are using Retrofit 2.0 for do some task in it. One of my function is like below

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();
            }
        }
    });

}

I want show toast when call is success. I have tried to put it in many place but its not showing. I have tried to put it after this line etc

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);
                    }

This is response model

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;
}

}

But its not showing anything. However my task is going completed without any issue. Can somebody please check and tell me what is issue in it ?

Thanks

Upvotes: 1

Views: 707

Answers (1)

Rajesh Panchal
Rajesh Panchal

Reputation: 1170

Make sure you're getting success as a true and it's in boolean because in your model class you've taken success as a boolean

Upvotes: 1

Related Questions