【发布时间】:2019-03-30 11:44:38
【问题描述】:
我是 Java 和 Android 的新手,所以我需要您的帮助。 我在我的应用程序中实现了 JSoup 以从网页中获取它并在文本视图中显示(我在片段中操作,但我认为在这种情况下它与标准活动相同)。
<body marginwidth="0" marginheight="0">
<h1></h1>
<p class="testoprezzo">0.5516 </p>
</body>
我只需要 0.5516
我不知道该怎么做。你能帮助我吗? 这是我已经编写的代码:class fetcher extends AsyncTask<Void,Void, Void> {
@Override
protected Void doInBackground(Void... arg0) {
try {
String value = "https://mywebpage.net/";
Document document = Jsoup.connect(value).followRedirects(false).timeout(30000).get();
Element p= document.select ("p.testoprezzo").first();
((Globals)getApplication()).setValore(p.text());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
TextView valore = findViewById(R.id.textView4);
valore.setText(((Globals)getApplication()).getValore());
}
}
提前感谢您!
【问题讨论】:
标签: java android android-fragments android-asynctask jsoup