public class MainActivity extends Activity {
TextView tv; final String URL = "http://www.mtn.co.ug/Mobile-Plans/PayAsYouGo/MTN-PerMinute.aspx";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.textView);
new MyTask().execute(URL);
}
private class MyTask extends AsyncTask<String, Void, String> {
ProgressDialog prog;
String title = "";
@Override
protected void onPreExecute() {
prog = new ProgressDialog(MainActivity.this);
prog.setMessage("Loading....");
prog.show();
}
@Override
protected String doInBackground(String... params) {
try {
Document Doc= Jsoup.connect(params[0]).get();
//timeout(90000).ignoreHttpErrors(true);
//title = Doc.title();
for (Element Yello: Doc.select("div tbody:contains(Bundle):eq(6) tr td")) {
System.out.println(Yello.text());
tv.setText(Yello.text());
title = Yello.toString();
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
tv.setText(title);
prog.dismiss();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
조지 감사합니다. 하지만 앱이 실행될 때마다 시간이 초과됩니다. asynchTask도 표시 할 수 있습니다. – Kinny
좋습니다. 다른 질문입니다. 도움이된다면 대답으로 표시하십시오. 힌트, 당신은 인터넷에서 천천히 또는 웹 사이트가 테이블에 너무 많은 데이터를 가지고 사이트에서 다운로드 한 dat을 처리하기 위해 asyntask 메서드 안에 넣어해야합니다. 또한 시간 초과 요청을 늘리십시오. 이것도 확인해보십시오. http://stackoverflow.com/questions/7083680/how-to-use-asynctask-for-jsoup-parser. 감사합니다 – ImGeorge
내 코드는 위에 첨부되어 있지만 결과가 표시되지 않습니다. – Kinny