2017-01-26 29 views
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; 
} 

}

但它不顯示任何。不過我的任務沒有任何問題。有人可以檢查並告訴我它有什麼問題嗎?

感謝

+0

發表您迴應 –

+0

嘗試註釋掉的代碼的setResult( RESULT_OK);並完成(); overridePendingTransition(R.anim.fade_in,R.anim.fade_out);.檢查烤麪包是否可見。如果是,則將Toast.makeText放在setResult上面... –

+0

未示出烤麪包的原因是因爲活動在請求完成後立即完成。如果你想看到吐司評論,然後出其他3行。 – akash93

回答

1

確保您獲得成功,作爲一個真正的,它是在布爾因爲在你的模型類,你已經採取了成功的布爾

+0

謝謝......服務器端存在問題,因爲我們沒有從中獲得成功消息。現在它已被修復......上面的代碼中沒有任何問題。謝謝 –