java - Making WebViews work with Master Details -


this android studio v2.3. want have master detail flow click 1 of items on list , brings me website. after looking @ different recommendations, app still force quits or "doesn't respond" whenever click items on list. please help!

webpagedetailfragment.java code:

package com.example.jasperzhu.moremorelearning;  import android.app.activity; import android.support.design.widget.collapsingtoolbarlayout; import android.os.bundle; import android.support.v4.app.fragment; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import com.example.jasperzhu.moremorelearning.dummy.dummycontent; import android.webkit.webview; import android.webkit.webviewclient;  /**  * fragment representing single webpage detail screen.  * fragment either contained in {@link webpagelistactivity}  * in two-pane mode (on tablets) or {@link webpagedetailactivity}  * on handsets.  */ public class webpagedetailfragment extends fragment {     /**      * fragment argument representing item id fragment      * represents.      */     public static final string arg_item_id = "item_id";      /**      * dummy content fragment presenting.      */     private dummycontent.dummyitem mitem;      /**      * mandatory empty constructor fragment manager instantiate      * fragment (e.g. upon screen orientation changes).      */     public webpagedetailfragment() {     }      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          if (getarguments().containskey(arg_item_id)) {             // load dummy content specified fragment             // arguments. in real-world scenario, use loader             // load content content provider.             mitem = dummycontent.item_map.get(getarguments().getstring(arg_item_id));              activity activity = this.getactivity();             collapsingtoolbarlayout appbarlayout = (collapsingtoolbarlayout) activity.findviewbyid(r.id.toolbar_layout);             if (appbarlayout != null) {                 appbarlayout.settitle(mitem.content);             }         }     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         view rootview = inflater.inflate(r.layout.webpage_detail, container, false);          if (mitem != null) {             webview view = (webview) rootview.findviewbyid(r.id.webpage);             view.setwebviewclient(new webviewclient());             view.getsettings().setjavascriptenabled(true); //for web using javascript "youtube.com"             view.loadurl(mitem.address);             view.setlayertype(view.layer_type_hardware, null);         }          return rootview;      }   } 

dummycontent.java code:

import java.util.arraylist; import java.util.hashmap; import java.util.list; import java.util.map;  /**  * helper class providing sample content user interfaces created  * android template wizards.  * <p>  * todo: replace uses of class before publishing app.  */ public class dummycontent {      public static final list<dummyitem> items = new arraylist<dummyitem>();      public static final map<string, dummyitem> item_map = new hashmap<string, dummyitem>();      static {         additem(new dummyitem("google", "google", "www.google.com"));         additem(new dummyitem("bing", "bing", "www.bing.com"));         additem(new dummyitem("baidu", "baidu", "www.baidu.com"));     }      private static void additem(dummyitem item) {         items.add(item);         item_map.put(item.id, item);     }      private static string makedetails(int position) {         stringbuilder builder = new stringbuilder();         builder.append("details item: ").append(position);         (int = 0; < position; i++) {             builder.append("\nmore details information here.");         }         return builder.tostring();     }      public static class dummyitem {         public final string id;         public final string content;         public string address;          public dummyitem(string id, string content, string address) {             this.id = id;             this.content = content;             this.address = address;         }          @override         public string tostring() {             return content;         }      } } 

thanks again!


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? -