gpt4 book ai didi

android - 我正在尝试从 TextView 中的 mysql 加载数据

转载 作者:行者123 更新时间:2023-11-29 20:16:54 24 4
gpt4 key购买 nike

这是我的代码。请帮我找出错误。我在 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:

最佳答案

看起来您在findViewsById()之前调用了new GetReclamationDetails().execute();。另外,请在 onPostExecuteonProgressUpdate 中更新您的 UI,并尝试调用您的 View ,例如:ActivityName.class.yourView.setText() 希望这会有所帮助。

关于android - 我正在尝试从 TextView 中的 mysql 加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39706159/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com