我想在滑雪度假區的過去24小時內在TextView
中顯示Snow。我使用了CSS路徑並嘗試了其他方式,但沒有任何反應,TextView
不顯示任何內容。使用Jsoup在TextView中顯示單元格表格數據
的網頁:http://www.arizonasnowbowl.com/resort/snow_report.php
的CSS路徑:#container的> div.right> table.interior> TBODY> TR:第n個孩子(2)> td.infoalt
private class Description extends AsyncTask<Void, Void, Void> {
String desc;
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(Snowreport.this);
mProgressDialog.setTitle("Snow Report");
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
try {
// Connect to the web site
Document document = Jsoup.connect(url).get();
Elements elms = document.select("td.infoalt");
for(Element e:elms)
if(e.className().trim().equals("infoalt"))
//^^^<--trim is required as,
// their can be leading and trailing space
{
TextView txtdesc = (TextView) findViewById(R.id.snowp24);
txtdesc.setText((CharSequence) e);
}
mProgressDialog.dismiss();
} catch (IOException e1) {
e1.printStackTrace();
}
return null;
}
謝謝!!!!我收到消息「無法解析符號響應」 – 2015-02-08 14:48:24
您需要在上面的代碼之前添加一個Jsoup響應。最終Connection.Response響應= Jsoup.connect(mUrl).method(Connection.Method.POST).timeout(10000).execute(); – 2015-02-08 16:53:55