In my android application I need to call two functions in a web service. I need to display both the values in one page. When I did for one function it was working fine.. but when I tried for second it is not working.. I am giving my code below.
class ProgressTask extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(R_Details.this);
pDialog.setMessage("Verifying the details... Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@SuppressWarnings("deprecation")
@Override
protected String doInBackground(String... args) {
url = "https://xxx.xxxx.com/appservice/d_service.asmx/mDetails?";
url2 = "https://xxx.xxxx.com/appservice/d_service.asmx/mGoDetails?";
SharedPreferences plnumber = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences login = getSharedPreferences(PREFS_NAME, 0);
pl = String.valueOf(pnumber.getString("pl","not found"));
cd = String.valueOf(login.getString("cid","not found"));
ud = String.valueOf(login.getString("uid","not found"));
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("pl", pl));
params.add(new BasicNameValuePair("cd", cd));
params.add(new BasicNameValuePair("ud", ud));
String paramString = URLEncodedUtils.format(params, "utf-8");
url += paramString;
url2 += paramString;
// TODO Auto-generated method stub
JSONParser jParser = new JSONParser();
JSONPars jPars = new JSONPars();
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);
JSONObject json2 = jPars.getJSONFromUrl(url2);
try {
final String st = json.getString(TAG_STATUS);
final String po = json.getString(TAG_PNO);
final String pt = json.getString(TAG_PAMT);
final String te = json.getString(TAG_TRAD);
final String me = json.getString(TAG_MD);
final String le = json.getString(TAG_LTE);
final String ph = json2.getString(TAG_PE);
final String pi = json2.getString(TAG_PE);
final String ir = json2.getString(TAG_IT);
final String rt = json2.getString(TAG_RE);
final String tt = json2.getString(TAG_TNT);
de = (TextView) findViewById(R.id.dd);
lt = (TextView) findViewById(R.id.ltd);
le = (TextView) findViewById(R.id.lted);
me = (TextView) findViewById(R.id.mad);
at = (TextView) findViewById(R.id.ad);
lo = (TextView) findViewById(R.id.tvr);
pe = (TextView) findViewById(R.id.pd);
it = (TextView) findViewById(R.id.id);
pe = (TextView) findViewById(R.id.pd);
re = (TextView) findViewById(R.id.rd);
tt = (TextView) findViewById(R.id.td);
runOnUiThread(new Runnable() {
@Override
public void run()
{
de.setText(trnsdate);
lt.setText(pledamt);
le.setText(ltradate);
me.setText(matdate);
at.setText(stat);
lo.setText(pledno);
pe.setText(pi);
it.setText(ir);
pe.setText(ph);
re.setText(rt);
tt.setText(tt);
}
});
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
// dismiss the dialog once got all details
pDialog.dismiss();
}
}
答案 0 :(得分:0)
There is issues in your code.
Move the following code to onPostExecute
method
de = (TextView) findViewById(R.id.dd);
lt = (TextView) findViewById(R.id.ltd);
le = (TextView) findViewById(R.id.lted);
me = (TextView) findViewById(R.id.mad);
at = (TextView) findViewById(R.id.ad);
lo = (TextView) findViewById(R.id.tvr);
pe = (TextView) findViewById(R.id.pd);
it = (TextView) findViewById(R.id.id);
pe = (TextView) findViewById(R.id.pd);
re = (TextView) findViewById(R.id.rd);
tt = (TextView) findViewById(R.id.td);
runOnUiThread(new Runnable() {
@Override
public void run()
{
de.setText(trnsdate);
lt.setText(pledamt);
le.setText(ltradate);
me.setText(matdate);
at.setText(stat);
lo.setText(pledno);
pe.setText(pi);
it.setText(ir);
pe.setText(ph);
re.setText(rt);
tt.setText(tt);
}
});
Reason: Don't use UI widgets in doInBackGround
method