2013-07-12 17 views
0

的我無法甚至傳遞一個參考佈局之後訪問在異步類片段的XML元素等TextViews。在onPostExecute之前它工作得很好。 我無法看到的視圖。無法訪問XML元素在異步類片段

public class Enq extends SherlockFragment 
{ 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
    View rootView=inflater.inflate(R.layout.activity_single_track,container,false); 

    Bundle bundle = this.getArguments(); 
    query_id = bundle.getString("queryID"); 
    query_type = bundle.getString("queryType"); 
    query_subject = bundle.getString("querySubject"); 
    query_name = bundle.getString("queryName"); 

    //TextView tc =(TextView) rootView.findViewById(R.id.check); 
    //tc.setText(query_id); 
    Context cont = getActivity(); 
    new LoadSingleMsg(cont,rootView).execute(); 

    return rootView; 
} 

class LoadSingleMsg extends AsyncTask<String, String, String> { 

     private Context mContext; 
     private View rootView; 
     public LoadSingleMsg(Context context, View rootView){ 
      this.mContext=context; 
      this.rootView=rootView; 
     } 

     /** 
     * Before starting background thread Show Progress Dialog 
     * */ 
     @Override 
     protected void onPreExecute() { 
      super.onPreExecute(); 
      pDialog = new ProgressDialog(getActivity()); 
      pDialog.setMessage("Loading message..."); 
      pDialog.setIndeterminate(false); 
      pDialog.setCancelable(false); 
      pDialog.show(); 
     } 

     /** 
     * getting song json and parsing 
     * */ 
     protected String doInBackground(String... args) { 
      // Building Parameters 
      params.add(new BasicNameValuePair("MID",query_id)); 


      // getting JSON string from URL 
      String json = jsonParser.makeHttpRequest(URL_MSGDET, "POST", 
        params); 


      try {    
       JSONObject jObj = new JSONObject(json); 
       if(jObj != null){ 

        name = jObj.getString(TAG_SNAME); 
        subject = jObj.getString(TAG_SUBJECT); 
        message = jObj.getString(TAG_MESSAGE);     

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

      return null; 
     } 

     /** 
     * After completing background task Dismiss the progress dialog 
     * **/ 
     protected void onPostExecute() { 
      // dismiss the dialog after getting song information 
      pDialog.dismiss(); 

         System.out.println("nam"+ name); 
         TextView txt_sname = (TextView)rootView.findViewById(R.id.name); 
         TextView txt_message = (TextView) rootView.findViewById(R.id.message); 
         TextView txt_subject = (TextView) rootView.findViewById(R.id.subject); 

         // displaying data in view 
         txt_sname.setText(name); 
         txt_message.setText(Html.fromHtml("<b>Message:</b> " + message)); 
         txt_subject.setText(Html.fromHtml("<b>Subject:</b> " + subject)); 


         } 

      } 
+0

它是如何不工作? LogCat中的任何內容?如果是這樣,請張貼它。在logcat的 –

+0

@GrahamPovey沒什麼,觀點沒有得到呈現。只有進展對話正在顯示。 – user2290189

回答

0

嘗試添加調用超級的第一件事就是在PostExecute:

@Override 
protected void onPostExecute(String result) { 
    super.onPostExecute(result); 

    pDialog.dismiss(); 
... 
} 
+0

您可能需要聲明'doInBackground'爲'@ Override'過,但是,這並不通常所說的超級。 –

+0

謝謝!它爲我工作:) – user2290189