这是我的代码。请帮助我找到错误。我将所有回收均加载到ListView
中,并且可以正常工作,但是当我单击单个回收以显示详细信息时,它将无法正常工作,它会显示布局,但不会在textview中显示信息。
public class EditReclamationActivity extends Activity {
TextView txtName;
TextView txtType;
TextView txtDesc;
String rid;
Progress Dialog
private ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
private static final String url_reclamation_details = "http://192.168.1.67/android_connect/get_product_details.php";
private static final String TAG_SUCCESS = "success";
private static final String TAG_RECLAMATION = "reclamation";
private static final String TAG_RID = "rid";
private static final String TAG_NAME = "name";
private static final String TAG_TYPE = "type";
private static final String TAG_DESCRIPTION = "description";
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_reclamation);
Intent i = getIntent();
rid = i.getStringExtra(TAG_RID);
new GetReclamationDetails().execute();
txtName = (TextView) findViewById(R.id.name1);
txtType = (TextView) findViewById(R.id.type1);
txtDesc = (TextView) findViewById(R.id.description1);
}
class GetReclamationDetails extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(EditReclamationActivity.this);
pDialog.setMessage("Loading reclamation details. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String doInBackground(String... params) {
try {
List<NameValuePair> pars = new ArrayList<NameValuePair>();
pars.add(new BasicNameValuePair("rid", rid));
final JSONObject json = jsonParser.makeHttpRequest(
url_reclamation_details, "GET", pars);
Log.d("Single Rec Details", json.toString());
final int success = json.getInt(TAG_SUCCESS);
runOnUiThread(new Runnable() {
public void run() {
if (success == 1) {
try {
JSONArray recObj = json.getJSONArray(TAG_RECLAMATION);
JSONObject reclamation = recObj.getJSONObject(0);
txtName.setText(reclamation.getString(TAG_NAME)); txtType.setText(reclamation.getString(TAG_TYPE)); txtDesc.setText(reclamation.getString(TAG_DESCRIPTION));
} catch (JSONException e) {
}
} else {
}
}
});
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
}
}
}
This is the message error, data are loaded from mysql but not in android:
最佳答案
看起来像在new GetReclamationDetails().execute();
之前调用findViewsById()
一样。另外,在onPostExecute
或onProgressUpdate
中更新您的UI,然后尝试按如下方式调用视图:ActivityName.class.yourView.setText()
希望这会有所帮助。