繁体   English   中英

如何使用Jsoup从HTML将文本获取文本到TextView,没有按钮?

[英]How to get text from html to TextView with Jsoup, no buttons?

所以我写了这篇文章,但是Android Studio说“从不使用类新闻”,我在做什么错?

public class news extends AsyncTask<Void,Void,Void> {
    String words;
    @Override
    protected Void doInBackground(Void... params) {
      try{
         Document doc = Jsoup.connect("myurl").get();
         Elements ele = doc.select("div#home-right");
         words = ele.text();
      }catch(Exception e){e.printStackTrace();}
      return null;
    }   
    TextView.setText(words);
}

您必须致电“新闻”类。 因此,在活动中的onCreate方法中调用new news(this).execute();。 记住用大写字母上课。

在您的活动课中,输入以下代码:

news n = new news();
n.execute();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM