TextViews
即使在传递布局引用后,我也无法访问像片段的异步类中的 xml 元素。在 onPostExecute 之前它工作得非常好。我无法看到景色。
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));
}
}