Verwendung von WebView in Fragment

kürzlich begann ich eine Android-app mit WebView. Die app ist gewachsen und ich habe die Aktivität mit WebView auf tabbed-Aktivität unter Verwendung von Fragmenten und ViewPager. Und da begann mein Problem. Nach einigen Kopfschmerzen habe ich es endlich geschafft, wie die Anzeige der richtigen Fragmente für jede Registerkarte. Dann kopierte ich einfach den code für die "Webansicht" aus, um ein fragment, aber das fragment nicht mit der web-Seite, die ich möchte. Jede Hilfe wird dankbar sein!

Hier der code:

fragment mit webView

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class WebViewFragment extends Fragment {

    public WebView mWebView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        mWebView = (WebView) mWebView.findViewById(R.id.webview);
        mWebView.loadUrl("google.com");

        //Enable Javascript
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        //Force links and redirects to open in the WebView instead of in a browser
        mWebView.setWebViewClient(new WebViewClient());

        return inflater.inflate(R.layout.fragment_bugtracker, container, false);
    }
}

- und xml -

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Tabs$BugtrackerFragment">

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>
  • wie ist das ein Duplikat?
InformationsquelleAutor tomaset22 | 2015-07-01
Schreibe einen Kommentar