I was trying to make a very basic program to load the web page on a web view in the onCreate()
method of my main activity, but it always asks to me load that url on my inbuilt web browsers. How can I load the web page on a webview?
Asked
Active
Viewed 1,138 times
1

Joel Peltonen
- 13,025
- 6
- 64
- 100
-
What code you had done for that ? – Mehul Ranpara Jan 29 '14 at 12:44
-
You need to show the code you are using. – jeremyjjbrown Feb 07 '14 at 03:16
-
possible duplicate of [how to load a url to webview in android?](http://stackoverflow.com/questions/11288611/how-to-load-a-url-to-webview-in-android) – jww Feb 07 '14 at 11:31
3 Answers
1
You can try below code.
public class Main extends Activity {
private WebView mWebview ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWebview = new WebView(this);
mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript
final Activity activity = this;
mWebview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
}
});
mWebview .loadUrl("http://www.google.com");
setContentView(mWebview );
}
}

InnocentKiller
- 5,234
- 7
- 36
- 84
0
Yes, you are required to load it through WebViewClient
Check and try below example given on WebView doc:
webview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
webview.loadUrl("http://developer.android.com/");

Paresh Mayani
- 127,700
- 71
- 241
- 295
0
public class WebViewController extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
webView.setWebViewClient(new WebViewController());

Rajan
- 1,069
- 1
- 9
- 17