1
我正在學習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();
}
}
});
}
我想在呼叫成功時顯示祝酒。我試圖把它放在很多地方,但沒有顯示。我試圖把它這條線等
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;
}
}
但它不顯示任何。不過我的任務沒有任何問題。有人可以檢查並告訴我它有什麼問題嗎?
感謝
發表您迴應 –
嘗試註釋掉的代碼的setResult( RESULT_OK);並完成(); overridePendingTransition(R.anim.fade_in,R.anim.fade_out);.檢查烤麪包是否可見。如果是,則將Toast.makeText放在setResult上面... –
未示出烤麪包的原因是因爲活動在請求完成後立即完成。如果你想看到吐司評論,然後出其他3行。 – akash93