【问题标题】:Detail view of listview列表视图的详细视图
【发布时间】:2015-03-06 05:53:42
【问题描述】:

这是我的异步任务。我想显示列表视图单击的详细视图。在文本视图中显示数据时出现一些错误。我知道我们无法访问 doInBackground 中的 UI。我不知道如何在 OnpostExecute 中执行。帮帮我

class Enquiryview extends AsyncTask<String, Void, JSONObject> {

     protected void onPreExecute() {
         super.onPreExecute();
         pDialog = new ProgressDialog(EnquiryDetail.this);
        // pDialog.setMessage("Loding...");
         pDialog.setIndeterminate(false);
         pDialog.setCancelable(true);
         pDialog.show();
     }
        protected JSONObject doInBackground(String... args) {
            List<NameValuePair> params = new ArrayList<NameValuePair>();


           // final String URL_LIST = "http://staging.homeneedsonline.com/ws/ws_address_detail.php?user_id="+ userid1+"";
            final String URL_LIST = "http://staging.homeneedsonline.com/ws/ws_enq_detail.php?ser_enq_id="+ enq_id+"";

               System.out.println(URL_LIST);
            JSONParser jsonParser = new JSONParser();    

           final JSONObject json = jsonParser.getJSONFromUrl(URL_LIST, get, params);



            System.out.println("enq----do in ---"+json);
            try {    
               String res = json.getString(KEY_SUCCESS); 
                 System.out.println("enq---------------is"+enq_id);
                int res1 = Integer.parseInt(res);
               if (res1 == 1) {
                  // String res = json.getString(KEY_SUCCESS); 
                   //System.out.println(res);

                    JSONObject jsonObject = json.getJSONObject("detail");

                     // setListAdapter(mAdapter);

                     // JSONArray json1=new JSONArray("data");

                       //Log.d("Address JSON: ", "> " + albums);

                     // Storing each json item values in variable
                      final String enqid = jsonObject.getString(ENQID);
                       String enqdate = jsonObject.getString(ENQ_DATE);
                       String status = jsonObject.getString(STATUS);
                       String usc = jsonObject.getString(USC);
                       String amount = jsonObject.getString(AMOUNT);

                    String address = jsonObject.getString(ENQ_ADDRESS);
                     String city = jsonObject.getString(CITY);
                    String state = jsonObject.getString(STATE);


                System.out.println(enqid);
                System.out.println(enqdate);

                System.out.println(usc);

                System.out.println(address);

                System.out.println(city);

                System.out.println(state);
               // service.setText();
                amounttext.setText(amount);
                //exname.setText();
                statustext.setText(status);
                addresstext.setText(address);

                citytext.setText(city);

                statetext.setText(state);

                //billno.setText();
                usctext.setText(usc);
                date.setText(enqdate);
                enqidtext.setText(enqid);



               }
               else
               {
                   Log.d("Addressssssssssssssssssssssssssssssssss: ", "null");


               }

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

            return json;
        }

        }

        protected void onPostExecute(final JSONObject json1) {
            // check for login response
           /// System.out.println("enq----on post ---"+json);

            pDialog.dismiss();
               // Check your log cat for JSON reponse

        }

【问题讨论】:

    标签: android listview android-asynctask


    【解决方案1】:
    class Enquiryview extends AsyncTask<String, Void, JSONObject> {
    
    
    final JSONObject json;
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(EnquiryDetail.this);
       // pDialog.setMessage("Loding...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
    }
       protected JSONObject doInBackground(String... args) {
           List<NameValuePair> params = new ArrayList<NameValuePair>();
    
    
          // final String URL_LIST = "http://staging.homeneedsonline.com/ws/ws_address_detail.php?user_id="+ userid1+"";
           final String URL_LIST = "http://staging.homeneedsonline.com/ws/ws_enq_detail.php?ser_enq_id="+ enq_id+"";
    
              System.out.println(URL_LIST);
           JSONParser jsonParser = new JSONParser();    
    
          json = jsonParser.getJSONFromUrl(URL_LIST, get, params);
    
          return null;
    
    
       }
    
       protected void onPostExecute(final JSONObject json1) {
           // check for login response
          /// System.out.println("enq----on post ---"+json);
    
           System.out.println("enq----do in ---"+json);
           try {    
              String res = json.getString(KEY_SUCCESS); 
                System.out.println("enq---------------is"+enq_id);
               int res1 = Integer.parseInt(res);
              if (res1 == 1) {
                 // String res = json.getString(KEY_SUCCESS); 
                  //System.out.println(res);
    
                   JSONObject jsonObject = json.getJSONObject("detail");
    
                    // setListAdapter(mAdapter);
    
                    // JSONArray json1=new JSONArray("data");
    
                      //Log.d("Address JSON: ", "> " + albums);
    
                    // Storing each json item values in variable
                     final String enqid = jsonObject.getString(ENQID);
                      String enqdate = jsonObject.getString(ENQ_DATE);
                      String status = jsonObject.getString(STATUS);
                      String usc = jsonObject.getString(USC);
                      String amount = jsonObject.getString(AMOUNT);
    
                   String address = jsonObject.getString(ENQ_ADDRESS);
                    String city = jsonObject.getString(CITY);
                   String state = jsonObject.getString(STATE);
    
    
               System.out.println(enqid);
               System.out.println(enqdate);
    
               System.out.println(usc);
    
               System.out.println(address);
    
               System.out.println(city);
    
               System.out.println(state);
              // service.setText();
               amounttext.setText(amount);
               //exname.setText();
               statustext.setText(status);
               addresstext.setText(address);
    
               citytext.setText(city);
    
               statetext.setText(state);
    
               //billno.setText();
               usctext.setText(usc);
               date.setText(enqdate);
               enqidtext.setText(enqid);
    
    
    
              }
              else
              {
                  Log.d("Addressssssssssssssssssssssssssssssssss: ", "null");
    
    
              }
    
        } catch (JSONException e) {
            e.printStackTrace();
        }
    
           return ;
       }
    
    
           pDialog.dismiss();
              // Check your log cat for JSON reponse
    
       }
    

    试试这个

    【讨论】:

    • 在 OnPostexecute 中打印的 json 为空。
    • 它的 fyn bcz json 对象是全局变量
    • 或者你可以使用return json;也是。
    【解决方案2】:

    您需要从 doInBackground 方法返回 JsonObject ,并且无论您正在执行 doInBackground 什么 json 解析,您都需要将其移至 onPostExecute() 方法。 如果对你有帮助,请告诉我

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-18
      • 2016-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-10
      • 2020-10-30
      • 1970-01-01
      相关资源
      最近更新 更多