Webview in android suddenly stops when button is pressed -
package com.example.karla; import android.annotation.suppresslint; import android.app.activity; import android.graphics.bitmap; import android.os.bundle; import android.webkit.webview; import android.webkit.webviewclient; public class webviewactivity extends activity { private webview webview; @suppresslint("setjavascriptenabled") public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.webview); webview.setwebviewclient(new mywebclient()); webview = (webview) findviewbyid(r.id.webview1); webview.getsettings().setjavascriptenabled(true); webview.loadurl("http://www.google.com"); }
}
class mywebclient extends webviewclient { @override public void onpagestarted(webview view, string url, bitmap favicon) { // todo auto-generated method stub super.onpagestarted(view, url, favicon); }
@override public boolean shouldoverrideurlloading(webview view, string url) { // todo auto-generated method stub view.loadurl(url); return true; }
}
package com.example.karla; import android.app.activity; import android.content.context; import android.content.intent; import android.os.bundle; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; public class mainactivity extends activity { private button button; public void oncreate(bundle savedinstancestate) { final context context = this; super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); button = (button) findviewbyid(r.id.buttonurl); button.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { intent intent = new intent(context, webviewactivity.class); startactivity(intent); } }); }
}
my android application stops when press button. want website load in webview not in browser override urlloading. dont know do? should do?
@override public boolean shouldoverrideurlloading(webview view, string url) { // todo auto-generated method stub view.loadurl(url); return true; }
if want let webview load page, don't view.loadurl()
: return false
.
@override public boolean shouldoverrideurlloading(webview view, string url) { return false; }
returning true
prevent webview loading url means should instead. example, instead of navigating "help" page, show screen inside app help.
Comments
Post a Comment