0

I have created a page which has link to a page of a website. So for showing that on I have used a WebView and it works fine.

My Problem is that when I click on any link given on that webpage, the link opens in phone's default browser view. But I want all the links to be opened in my created WebView.

Have I made any mistake or it is right..

Please Help Me My code is as follows...

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        Log.e("------------", ".........................................................................................");
        setContentView(R.layout.terms_of_use_web_view_page);

        btn_back = (Button) findViewById(R.id.terms_of_use_button_back);
        btn_back.setOnClickListener(this); 
        webview = (WebView)findViewById(R.id.terms_of_use_webview);
        webview.getSettings().setJavaScriptEnabled(false);
        webview.loadUrl("http://www.oomphlink.com/terms-of-use/");


    }
2
  • 1
    this should be an answer, but I'll comment it anyway.. Research on WebViewClient and shouldOverrideUrlLoading.
    – junmats
    Commented Jun 10, 2011 at 7:04
  • Ya you should go with WebViewClient. Commented Jun 10, 2011 at 7:08

2 Answers 2

3

Try specifying your own WebViewClient:

WebView webView = (WebView)findViewById( R.id.terms_of_use_webview );
webView.setWebViewClient( new WebViewClient() 
{
    @Override
    public boolean shouldOverrideUrlLoading( WebView view, String url )
    {
        view.loadUrl( url );
        return true;
    }
});

To further understand why this is necessary have a look at the documentation for the shouldOverrideUrlLoading method.

1
wv.setWebViewClient(new MyWebViewClient());

public class MyWebViewClient extends WebViewClient{
}

link for more info...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.