为什么条件不能在我的AsyncTask onPostExecute中工作

时间:2014-04-17 15:16:35

标签: android web-services android-asynctask

我在AsyncTask的doinbackground()中获得了成功响应。当我检查postExecute()上的equalignorecase时它没有进入里面。下面是我的代码。我可以进入下一步,问题是什么,请帮助我。

   class Service extends AsyncTask<String, String, String>
    {
        String responseStr = null;
        String res="Failure";
        ProgressDialog pd;
        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
            pd = new ProgressDialog(MainActivity.this);
            pd.setMessage("Loading..");
            pd.show();
        }
        @Override
        protected String doInBackground(String... args) {
          try {

            HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(Config.POST_URL);
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
                nameValuePairs.add(new BasicNameValuePair("loantype",mortageText));
                if(mortageText.equalsIgnoreCase("Refinanace"))
                nameValuePairs.add(new BasicNameValuePair("loanamount",h_borrow));
                nameValuePairs.add(new BasicNameValuePair("esthomevalue",estimatedHM));
                nameValuePairs.add(new BasicNameValuePair("creditscore",thirdViewBoxText));
                if(mortageText.equalsIgnoreCase("Refinanace"))
                nameValuePairs.add(new BasicNameValuePair("currentinterstrate",Integer.toString(intrest)));
                nameValuePairs.add(new BasicNameValuePair("fname",firstNameText));
                nameValuePairs.add(new BasicNameValuePair("lname",lastNameText));
                nameValuePairs.add(new BasicNameValuePair("address",streetAddressText));
                nameValuePairs.add(new BasicNameValuePair("email",emailText));
                nameValuePairs.add(new BasicNameValuePair("city",cityText));
                nameValuePairs.add(new BasicNameValuePair("state",stateText));
                nameValuePairs.add(new BasicNameValuePair("zip",zipText));
                nameValuePairs.add(new BasicNameValuePair("phone",phoneText));
                nameValuePairs.add(new BasicNameValuePair("currentyinfha",militaryText));
                nameValuePairs.add(new BasicNameValuePair("miltaryservice",militaryserviceText));

                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));                  
                try {
                    HttpResponse response = httpclient.execute(httppost);
                    responseStr = EntityUtils.toString(response.getEntity());

                } catch (ClientProtocolException e) {
                    e.printStackTrace();
                    return null;
                }

             }catch (Exception e) {
                e.printStackTrace();
            }

            return responseStr;
        }
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            pd.cancel();
            if(result.equalsIgnoreCase("Success"))
            {
                dialogGreatNews();

            }

        }
    }

1 个答案:

答案 0 :(得分:0)

修剪空白区域或检查是否存在换行符号

if(result.trim().equalsIgnoreCase("Success")) {

    dialogGreatNews();

}