0
如何在使用JSoup解析器的示例中應用AsyncTasc?只是我嘗試使用線程,但是這不起作用,從Android版本4.x.x開始。也許有人知道,下面的例子是如何添加AsyncTasc? 感謝您的提前。jsoup解析器中的AsyncTasc?
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class JSoupStudyActivity extends Activity {
// blog url
static final String BLOG_URL = "http://xjaphx.wordpress.com/";
@Override
public void onCreate(Bundle savedInstanceState) {
// set layout view
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// process
try {
((TextView)findViewById(R.id.tv)).setText(getBlogStats());
} catch (Exception ex) {
((TextView)findViewById(R.id.tv)).setText("Error");
}
}
protected String getBlogStats() throws Exception {
String result = "";
// get html document structure
Document document = Jsoup.connect(BLOG_URL).get();
// selector query
Elements nodeBlogStats = document.select("div#blog-stats ul li");
// check results
if(nodeBlogStats.size() > 0) {
// get value
result = nodeBlogStats.get(0).text();
}
// return
return result;
}
}