【问题标题】:Jsoup and setText not working in android [duplicate]Jsoup和setText在android中不起作用[重复]
【发布时间】:2013-12-09 19:51:05
【问题描述】:

基本上,当我执行我的应用程序时,它要么崩溃,要么不显示任何文本或任何内容。 我在我的主要活动中使用 Fragments 和 viewPager,但导致问题的类是这个:

public class DailyWord extends Fragment {

Document doc;
String data;
TextView t;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saveInstanceState) {
    View mainView = inflater.inflate(R.layout.activity_daily_word, container, false);

    try {
        doc = Jsoup.connect("http://www.urbandictionary.com/").get();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Element Worddata = doc.getElementsByClass("word").first();
    Element Worddata2 = Worddata.select("a[href]").first();
    String wordName = Worddata2.text();

    Element definition = doc.getElementsByClass("description").first();
    String define = definition.text();

    Element example = doc.getElementsByClass("example").first();
    String context = example.text();

    data = ("Word:\n" + wordName + "\n" + "Definition\n" + define + "\n" + "Context:\n" + context);

    t = (TextView) mainView.findViewById(R.id.textView1);
    t.setText(data);
        return mainView;
    }
}

【问题讨论】:

标签: java android textview jsoup settext


【解决方案1】:

下面应该是threadasynctask

doc = Jsoup.connect("http://www.urbandictionary.com/").get();

【讨论】:

  • 是否可以使用 viewPager 在片段中执行此操作?我很难让它工作。
  • @user1825241 你可以使用没有问题的线程或异步任务
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-15
  • 1970-01-01
  • 1970-01-01
  • 2017-10-19
相关资源
最近更新 更多