Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在片段文件上添加使用web视图?_Android_Android Fragments_Android Webview - Fatal编程技术网

Android 如何在片段文件上添加使用web视图?

Android 如何在片段文件上添加使用web视图?,android,android-fragments,android-webview,Android,Android Fragments,Android Webview,如何在我的片段上调用网络视图 正如你所看到的,我称之为,但我有一个错误。我想实现的是在我的应用程序上打开一个网页 以下是我使用的代码: package sampleapp.razen.com.sampleapp; import android.app.FragmentTransaction; import android.os.Bundle; import android.app.Fragment; import android.view.LayoutInflater; import and

如何在我的片段上调用网络视图 正如你所看到的,我称之为,但我有一个错误。我想实现的是在我的应用程序上打开一个网页

以下是我使用的代码:

package sampleapp.razen.com.sampleapp;


import android.app.FragmentTransaction;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;


/**
 * A simple {@link Fragment} subclass.
 */
public class GeoNjoroFragment extends Fragment {


    public GeoNjoroFragment() {

        // Required empty public constructor
    }



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

        View view = inflater.inflate(R.layout.fragment_geo_njoro, container, false);

        WebView myWebView = (WebView)view.findViewById(sampleapp.razen.com.sampleapp.R.id.webview);
        myWebView.getSettings().setLoadsImagesAutomatically(true);
        myWebView.getSettings().setJavaScriptEnabled(true);
        myWebView.getSettings().setDomStorageEnabled(true);
        myWebView.getSettings().setBuiltInZoomControls(true);
        myWebView.getSettings().setSupportZoom(true);
        myWebView.loadUrl("http://www.google.com/");
// Inflate the layout for this fragment
        return view;

    }



}
以下是我收到的错误图像:

试试这段代码。 首先,必须膨胀视图,然后使用findViewById()方法。 将此权限使用权限android:name=“android.permission.INTERNET”添加到Androidmanifest.xml文件

    View view = inflater.inflate(R.layout.fragment_geo_njoro, container, false);

    WebView myWebView = (WebView)view.findViewById(sampleapp.razen.com.sampleapp.R.id.webview);
        myWebView.getSettings().setLoadsImagesAutomatically(true);
        myWebView.getSettings().setJavaScriptEnabled(true);
        myWebView.getSettings().setDomStorageEnabled(true);
        myWebView.getSettings().setBuiltInZoomControls(true);
        myWebView.getSettings().setSupportZoom(true);
        myWebView.loadUrl("http://www.hivisasa.com/wb/nakuru/news/113249");
// Inflate the layout for this fragment
return view;
试试这个代码。 首先,必须膨胀视图,然后使用findViewById()方法。 将此权限使用权限android:name=“android.permission.INTERNET”添加到Androidmanifest.xml文件

    View view = inflater.inflate(R.layout.fragment_geo_njoro, container, false);

    WebView myWebView = (WebView)view.findViewById(sampleapp.razen.com.sampleapp.R.id.webview);
        myWebView.getSettings().setLoadsImagesAutomatically(true);
        myWebView.getSettings().setJavaScriptEnabled(true);
        myWebView.getSettings().setDomStorageEnabled(true);
        myWebView.getSettings().setBuiltInZoomControls(true);
        myWebView.getSettings().setSupportZoom(true);
        myWebView.loadUrl("http://www.hivisasa.com/wb/nakuru/news/113249");
// Inflate the layout for this fragment
return view;

如果不绑定视图,则webview找不到要绑定的视图,则应:

视图=充气机。充气(R.layout.fragment\u geo\u njoro,容器,假);
WebView myWebView=(WebView)view.findViewById(sampleapp.razen.com.sampleapp.R.id.WebView)

U不要绑定视图,这样webview就找不到要绑定的视图,它应该是:

视图=充气机。充气(R.layout.fragment\u geo\u njoro,容器,假);
WebView myWebView=(WebView)view.findViewById(sampleapp.razen.com.sampleapp.R.id.WebView)

它正在工作,但在我的android手机上,它显示的网页不可用。原因是什么(net;;ERR_CACHE_MISS)我试过了,只是看到了我发布的错误图片的更新having@FrancisNdirangu无法看到错误的图像单击此处是否已将此添加到清单中?。另请转到设置->应用程序管理器,选择您的应用程序并清除设备中应用程序的数据和缓存。它正在工作,但在我的android手机上显示的网页不可用。原因是什么(net;;ERR_cache_MISS)我已经试过了,只是看到了我的错误,我的帖子上的图像更新having@FrancisNdirangu无法看到错误的图像单击此处是否已将此添加到清单中?。也可以转到设置->应用程序管理器,选择您的应用程序并清除设备中应用程序的数据和缓存。如何在布局中打开html??如果是静态html字符串,您可以使用例如textView.setText(html.fromHtml(stringHtml));如果它是一个url,请使用webview来实现。如何在布局中打开html?如果它是一个静态html字符串,您可以使用例如textView.setText(html.fromHtml(stringHtml));如果它是一个url,请使用webview来做它。