我試圖更新3個接口元素,但它不會,也是我的實現正確嗎?doInBackground和更新界面
元素是txtName,txtClarety,txtDesc。 我不知道爲什麼......我不能明白的問題..
protected String doInBackground(String... params) {
// updating UI from Background Thread
Thread th = new Thread(new Runnable() {
public void run() {
// Check for success tag
int success;
try {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("pid", pid));
// getting dream details by making HTTP request
// Note that dream details url will use GET request
JSONObject json = jsonParser.makeHttpRequest(
url_dream_detials, "GET", params);
// check your log for json response
Log.d("Single Dream Details", json.toString());
// json success tag
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully received dream details
JSONArray dreamObj = json.getJSONArray(TAG_DREAM); // JSON Array
// get first dream object from JSON Array
JSONObject dream = dreamObj.getJSONObject(0);
// dream with this pid found
// Edit Text
txtName = (EditText) findViewById(R.id.inputEditName);
txtClarety = (EditText) findViewById(R.id.inputEditClarety);
txtDesc = (EditText) findViewById(R.id.inputEditDesc);
// display dream data in EditText
txtName.setText(dream.getString(TAG_NAME));
txtClarety.setText(dream.getString(TAG_CLARETY));
txtDesc.setText(dream.getString(TAG_DESCRIPTION));
}else{
// dream with pid not found
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
return null;
}
我喜歡的東西重命名我的投入,型動物的名字嘗試,但沒有...
的JSON執行是正確的。
你爲什麼在doinBackground()中使用其他線程? asynctask的doinBackground在單獨的線程中是成功的。 – Jithu 2014-09-23 13:15:21
我該怎麼辦? – John 2014-09-23 13:18:04