这是我的代码。请帮我找错。我在ListView
中加载了所有的回收并且它正常工作但是当我点击单个回收来显示它不起作用的详细信息时,它会向我显示布局但不在文本视图中显示信息。
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:
答案 0 :(得分:0)
看起来您new GetReclamationDetails().execute();
之前正在呼叫findViewsById()
。另外,在onPostExecute
或onProgressUpdate
更新您的用户界面,然后尝试调用您的视图:ActivityName.class.yourView.setText()
希望这会有所帮助。
答案 1 :(得分:0)
在方法的settext之前声明textview。
txtName = (TextView) findViewById(R.id.name1);
txtType = (TextView) findViewById(R.id.type1);
txtDesc = (TextView) findViewById(R.id.description1);
new GetReclamationDetails().execute();