如何在Fragment(WebView)中解析Jsoup数据

时间:2015-04-25 17:21:53

标签: android android-fragments android-webview jsoup

这是我的片段。当我打开片段时,没有错误或其他东西,但仍然是空白屏幕。 我怎样才能解决这个线程的问题?我只想从html解析并在WebView中显示。

   @Override
public View onCreateView(LayoutInflater inflater, ViewGroup
        container, Bundle savedInstanceState) {
    rootview = inflater.inflate(R.layout.menu2_layout_duyurular, container, false);
    downloadThread.start();
    WvFun();
    return rootview;
}

Thread downloadThread = new Thread() {
    public void run() {
        try {
            doc = Jsoup.connect(url_duyurular).get();
            div = doc.select("#yazilar").get(0);
            data += div;
            Log.i("Words", data);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
};

    public void WvFun() {
        Log.i("Working Fine", "WvFun is working.");
        WebView webView = (WebView) rootview.findViewById(R.id.duyurular_page);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadData(data, "text/html", "utf-8");
    }

我的logcat。如您所见,logcat中没有错误。但是“工作正常”日志早于“单词”日志。我如何解决这个问题以及如何使用线程。

04-25 19:44:14.042    9144-9144/com.bilgiislem.sems.beunapp I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
04-25 19:44:14.042    9144-9144/com.bilgiislem.sems.beunapp W/dalvikvm﹕ VFY: unable to resolve virtual method 12606: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
04-25 19:44:14.042    9144-9144/com.bilgiislem.sems.beunapp I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
04-25 19:44:14.042    9144-9144/com.bilgiislem.sems.beunapp W/dalvikvm﹕ VFY: unable to resolve virtual method 12612: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
04-25 19:44:14.052    9144-9144/com.bilgiislem.sems.beunapp I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
04-25 19:44:14.052    9144-9144/com.bilgiislem.sems.beunapp W/dalvikvm﹕ VFY: unable to resolve virtual method 10134: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
04-25 19:44:14.052    9144-9144/com.bilgiislem.sems.beunapp I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
04-25 19:44:14.052    9144-9144/com.bilgiislem.sems.beunapp W/dalvikvm﹕ VFY: unable to resolve virtual method 565: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
04-25 19:44:14.052    9144-9144/com.bilgiislem.sems.beunapp I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
04-25 19:44:14.052    9144-9144/com.bilgiislem.sems.beunapp W/dalvikvm﹕ VFY: unable to resolve virtual method 587: Landroid/content/res/TypedArray;.getType (I)I
04-25 19:44:14.052    9144-9144/com.bilgiislem.sems.beunapp I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawable
04-25 19:44:14.052    9144-9144/com.bilgiislem.sems.beunapp W/dalvikvm﹕ VFY: unable to resolve virtual method 528: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
04-25 19:44:14.052    9144-9144/com.bilgiislem.sems.beunapp I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawableForDensity
04-25 19:44:14.052    9144-9144/com.bilgiislem.sems.beunapp W/dalvikvm﹕ VFY: unable to resolve virtual method 530: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
04-25 19:44:14.812    9144-9144/com.bilgiislem.sems.beunapp I/dalvikvm-heap﹕ Grow heap (frag case) to 11.092MB for 6656416-byte allocation
04-25 19:44:14.952    9144-9144/com.bilgiislem.sems.beunapp E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 50
04-25 19:44:14.962    9144-9144/com.bilgiislem.sems.beunapp E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 53
04-25 19:44:14.962    9144-9144/com.bilgiislem.sems.beunapp E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 54
04-25 19:44:14.962    9144-9144/com.bilgiislem.sems.beunapp E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 54
04-25 19:44:14.962    9144-9144/com.bilgiislem.sems.beunapp E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 54
04-25 19:44:14.972    9144-9144/com.bilgiislem.sems.beunapp E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 56
04-25 19:44:18.492    9144-9144/com.bilgiislem.sems.beunapp I/chromium﹕ [INFO:library_loader_hooks.cc(112)] Chromium logging enabled: level = 0, default verbosity = 0
04-25 19:44:18.492    9144-9144/com.bilgiislem.sems.beunapp I/BrowserProcessMain﹕ Initializing chromium process, renderers=0
04-25 19:44:18.512    9144-9196/com.bilgiislem.sems.beunapp W/chromium﹕ [WARNING:proxy_service.cc(888)] PAC support disabled because there is no system implementation
04-25 19:44:18.572    9144-9144/com.bilgiislem.sems.beunapp I/Working Fine﹕ WvFun is working.
04-25 19:44:18.592    9144-9144/com.bilgiislem.sems.beunapp W/AwContents﹕ nativeOnDraw failed; clearing to background color.
04-25 19:44:18.852    9144-9144/com.bilgiislem.sems.beunapp I/chromium﹕ [INFO:async_pixel_transfer_manager_android.cc(56)] Async pixel transfers not supported
04-25 19:44:18.882    9144-9144/com.bilgiislem.sems.beunapp I/chromium﹕ [INFO:async_pixel_transfer_manager_android.cc(56)] Async pixel transfers not supported
04-25 19:44:18.882    9144-9144/com.bilgiislem.sems.beunapp E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 97
04-25 19:44:18.882    9144-9144/com.bilgiislem.sems.beunapp E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 102
04-25 19:44:18.892    9144-9144/com.bilgiislem.sems.beunapp E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 103
04-25 19:44:18.892    9144-9144/com.bilgiislem.sems.beunapp E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 104
04-25 19:44:18.892    9144-9144/com.bilgiislem.sems.beunapp E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 105
04-25 19:44:18.892    9144-9144/com.bilgiislem.sems.beunapp E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 106
04-25 19:44:18.892    9144-9144/com.bilgiislem.sems.beunapp E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 107
04-25 19:44:18.942    9144-9151/com.bilgiislem.sems.beunapp I/dalvikvm﹕ Total arena pages for JIT: 11
04-25 19:44:18.942    9144-9151/com.bilgiislem.sems.beunapp I/dalvikvm﹕ Total arena pages for JIT: 12
04-25 19:44:18.952    9144-9151/com.bilgiislem.sems.beunapp I/dalvikvm﹕ Total arena pages for JIT: 13
04-25 19:44:19.252    9144-9151/com.bilgiislem.sems.beunapp I/dalvikvm﹕ Total arena pages for JIT: 14
04-25 19:44:19.252    9144-9151/com.bilgiislem.sems.beunapp I/dalvikvm﹕ Total arena pages for JIT: 15
04-25 19:44:19.252    9144-9151/com.bilgiislem.sems.beunapp I/dalvikvm﹕ Total arena pages for JIT: 16
04-25 19:44:19.262    9144-9151/com.bilgiislem.sems.beunapp I/dalvikvm﹕ Total arena pages for JIT: 17
04-25 19:44:19.262    9144-9151/com.bilgiislem.sems.beunapp I/dalvikvm﹕ Total arena pages for JIT: 18
04-25 19:44:19.262    9144-9151/com.bilgiislem.sems.beunapp I/dalvikvm﹕ Total arena pages for JIT: 19
04-25 19:44:19.262    9144-9151/com.bilgiislem.sems.beunapp I/dalvikvm﹕ Total arena pages for JIT: 20
04-25 19:44:20.162    9144-9203/com.bilgiislem.sems.beunapp I/Yazilar﹕ <td id="yazilar">
    <div id="yazi-baslik">
    Duyurular
    </div>
    <ul>
    <li> <a href="/duyurular/1547/b-II-Arge-ve-Inovasyon-Proje-Pazari-b.html"><b>II. Arge ve İnovasyon Proje Pazarı</b></a> </li>
    </ul>
    <ul>
    <li> <a href="/duyurular/1600/tomerler-beude-bulusuyor.html">TÖMER'ler BEÜ'de buluşuyor</a> </li>
    </ul>
    <ul>
    <li> <a href="/duyurular/1599/vefat.html">Vefat</a> </li>
    </ul>
    <ul>
    <li> <a href="/duyurular/1588/EBYS-Kullanicilarina-Duyurulur.html">EBYS Kullanıcılarına Duyurulur</a> </li>
    </ul>
    <ul>
    <li> <a href="/duyurular/1598/Bulent-Ecevit-Universitesi-21-Uluslararasi-Bilim-ve-Genclik-Haftasi-Sportif-Etkinlikler-Duyurusu.html">Bülent Ecevit Üniversitesi 21. Uluslararası Bilim ve Gençlik Haftası Sportif Etkinlikler Duyurusu</a> </li>
    </ul>
    <ul>
    <li> <a href="/duyurular/1597/I-Karaelmas-Evde-Saglik-ve-Sosyal-Hizmetler-Sempozyumu.html">I. Karaelmas Evde Sağlık ve Sosyal Hizmetler Sempozyumu</a> </li>
    </ul>
    <ul>
    <li> <a href="/duyurular/1596/2015-ALES-Bahar-Donemi-Gorev-Talep-Islemleri.html">2015-ALES Bahar Dönemi Görev Talep İşlemleri</a> </li>
    </ul>
    <ul>
    <li> <a href="/duyurular/1595/Aday-Memur-Temel-Egitim-Sinav-Sonuclari.html">Aday Memur Temel Eğitim Sınav Sonuçları</a> </li>
    </ul>
    <ul>
    <li> <a href="/duyurular/1594/Radyo-Karaelmasta-Engelsiz-Universiteye-Dogru-Basliyor.html">Radyo Karaelmas'ta ""Engelsiz Üniversiteye Doğru" Başlıyor!</a> </li>
    </ul>
    <ul>
    <li> <a href="/duyurular/1592/1-Set-SPECTBT-SPECT-Gama-KameraBilgisayarli-Tomografi-Hibrid-Goruntuleme-Sistemi-Alimi.html">1 Set SPECTBT (SPECT Gama KameraBilgisayarlı Tomografi Hibrid Görüntüleme) Sistemi Alımı</a> </li>
    </ul>
    <ul>
    <li> <a href="/duyurular/1591/2015-2016-Akademik-Yili-Erasmus-Ogrenci-Ogrenim-ve-Staj-Hareketliligi-Yerlestirme-Sonuclari.html">2015-2016 Akademik Yılı Erasmus+ Öğrenci Öğrenim ve Staj Hareketliliği Yerleştirme Sonuçları</a> </li>
    </ul> </td>

1 个答案:

答案 0 :(得分:0)

现在我可以解析并在webview上显示。

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootview = inflater.inflate(R.layout.menu2_layout_duyurular, container, false);
    final WebView webView = (WebView) rootview.findViewById(R.id.duyurular_page);
    webView.getSettings().setJavaScriptEnabled(true);
   // webView.addJavascriptInterface(new MyJavaScriptInterface(this), "HtmlViewer");
    downloadThread.start();
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            webView.loadData(data, "text/html", null);
        }
    });

    webView.loadUrl(url_duyurular);

    return rootview;
}

Thread downloadThread = new Thread() {
    public void run() {
        try {

            doc = Jsoup.connect(url_duyurular).get();
            div = doc.select("#yazilar").get(0);
            data += div;
            Log.i("Words", data);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }