java - WebView in fragments -


i creating application android , need put webview in fragment have tried lot of codes , none works me. need help

this code of fragment when run application code in fragment when stops.

i not know if code brings default fragment since menu sections work when enter 1 has webview stops

    package org.protectorabaix;  import android.content.context; import android.net.uri; 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;   /**  * simple {@link fragment} subclass.  * activities contain fragment must implement  * {@link listadoanimales.onfragmentinteractionlistener} interface  * handle interaction events.  * use {@link listadoanimales#newinstance} factory method  * create instance of fragment.  */ public class listadoanimales extends fragment {      public webview mwebview;      // todo: rename parameter arguments, choose names match     // fragment initialization parameters, e.g. arg_item_number     private static final string arg_param1 = "param1";     private static final string arg_param2 = "param2";      // todo: rename , change types of parameters     private string mparam1;     private string mparam2;      private onfragmentinteractionlistener mlistener;      public listadoanimales() {         // required empty public constructor     }      /**      * use factory method create new instance of      * fragment using provided parameters.      *      * @param param1 parameter 1.      * @param param2 parameter 2.      * @return new instance of fragment listadoanimales.      */     // todo: rename , change types , number of parameters     public static listadoanimales newinstance(string param1, string param2) {         listadoanimales fragment = new listadoanimales();         bundle args = new bundle();         args.putstring(arg_param1, param1);         args.putstring(arg_param2, param2);         fragment.setarguments(args);         return fragment;     }      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         if (getarguments() != null) {             mparam1 = getarguments().getstring(arg_param1);             mparam2 = getarguments().getstring(arg_param2);         }     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {          view v=inflater.inflate(r.layout.fragment_listado_animales, container, false);         mwebview = (webview) v.findviewbyid(r.id.listado);         mwebview.loadurl("https://google.com");          // enable javascript         websettings websettings = mwebview.getsettings();         websettings.setjavascriptenabled(true);          // force links , redirects open in webview instead of in browser         mwebview.setwebviewclient(new webviewclient());          return v;     }      // todo: rename method, update argument , hook method ui event     public void onbuttonpressed(uri uri) {         if (mlistener != null) {             mlistener.onfragmentinteraction(uri);         }     }      @override     public void onattach(context context) {         super.onattach(context);         if (context instanceof onfragmentinteractionlistener) {             mlistener = (onfragmentinteractionlistener) context;         } else {             throw new runtimeexception(context.tostring()                     + " must implement onfragmentinteractionlistener");         }     }      @override     public void ondetach() {         super.ondetach();         mlistener = null;     }      /**      * interface must implemented activities contain      * fragment allow interaction in fragment communicated      * activity , potentially other fragments contained in      * activity.      * <p>      * see android training lesson <a href=      * "http://developer.android.com/training/basics/fragments/communicating.html"      * >communicating other fragments</a> more information.      */     public interface onfragmentinteractionlistener {         // todo: update argument type , name         void onfragmentinteraction(uri uri);     } } 


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -