Android: How to reload webview using a button -


i have created webview , loaded url.

if network connection not available loads custom url retry button.

  1. how can have button reload activity after user has network connection? (if easier calling activity , calling webview again works well.)

  2. have handled network connection not available code correctly?

    below code :

     import android.net.connectivitymanager;   import android.net.networkinfo;   import android.os.bundle;   import android.app.activity;   import android.view.menu;   import android.view.menuitem;   import android.webkit.webview;   import android.webkit.webviewclient;   import android.widget.toast;   import android.support.v4.app.navutils;   import android.annotation.targetapi;   import android.content.context;   import android.os.build;   public class webactivity extends activity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_web);       if(isnetworkstatusavailable (getapplicationcontext())) {          toast.maketext(getapplicationcontext(), "loading...", toast.length_short).show();         webview mywebview = (webview) findviewbyid(r.id.webview);         mywebview.loadurl("http://www.bing.com");          mywebview.setwebviewclient(new webviewclient() {              @override             public void onreceivederror(webview view, int errorcode,                     string description, string failingurl) {                 toast.maketext(getapplicationcontext(), "internet connection unavailable or " + description , toast.length_long).show();                 view.loadurl("file:///android_asset/mob.html");                 super.onreceivederror(view, errorcode, description, failingurl);             }          });      } else {          toast.maketext(getapplicationcontext(), "internet connection unavailable.", toast.length_long).show();         webview mywebview = (webview) findviewbyid(r.id.webview);         mywebview.loadurl("file:///android_asset/mob.html");        }      // show button in action bar.     setupactionbar(); }  public static boolean isnetworkstatusavailable (context context) {     connectivitymanager connectivitymanager = (connectivitymanager) context.getsystemservice(context.connectivity_service);     if (connectivitymanager != null)      {         networkinfo netinfos = connectivitymanager.getactivenetworkinfo();         if(netinfos != null)         if(netinfos.isconnected())              return true;     }     return false; }  } 

call webview.reload() inside button oncclicklistener reload url.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -