2

Possible Duplicate:
android webview click opens default browser

I have an application that opens a website in webview on start, however I can't seem to figure out how to keep any URL's that a user clicked on from opening in the browser.

Is there anyway to load the clicked URL inside the webview app?

EDIT - Using the below solution I still get an error on the private class "Illegal modifier for the local class MainScreenActivity; only abstract or final is permitted"... even if I try to rename this I get the same error

public class MainScreenActivity extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle icicle) {

    super.onCreate(icicle);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    WebView webview = new WebView(this);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.loadUrl("http://www.talk-of-the-tyne.co.uk");
    setContentView(webview);

    private class MainScreenActivity extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }
    }
}

Apologies if I am being thick about this, I just can't seem to get my head around this one

Community
  • 1
  • 1
Daf1892
  • 21
  • 1
  • 1
  • 3
  • You didn't implement the code correctly. Look at that answer again. You have to have an instance of WebViewClient, and you have to pass that to your webview. That's where shouldOverrideUrlLoading goes. – Mark B Feb 12 '11 at 19:28
  • Just change the line return true; to return false; inside public boolean shouldOverrideUrlLoading(WebView view, String url) Method. – Salman Khakwani Jul 13 '13 at 15:13
  • Why is your WebViewClient named as if it's an Activity class? – Christopher Perry Aug 29 '13 at 22:04
  • May this link might help you...http://stackoverflow.com/questions/2378800/clicking-urls-opens-default-browser?lq=1 – Sri Apr 08 '14 at 07:02

1 Answers1

4

try this code:

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
vnshetty
  • 20,051
  • 23
  • 64
  • 102