i try a simple webView appication. and this is my code :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView)findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://eepis-its.edu");
}
public class myWebClient extends WebViewClient{
public void onPageStarted(WebView view, String url, Bitmap favicon){
super.onPageStarted(view, url, favicon);
}
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
}
public boolean onKeyDown(int keyCode, KeyEvent event){
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()){
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
and, when i try to click hyperlink on that site, i redirected to mobile browser. why its happen? what i wanted is, when i click hyperlink its show on webview too.
please help me.
You have to override the standard behavior, which launches the browser when links are clicked. Use a WebViewClient
's shouldOverrideUrlLoading()
. There is an example of this in the SDK (copied below for convenience).
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
...then you just call someWebView.setWebViewClient(new HelloWebViewClient());
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With