Monday, January 11, 2016

Click on a link Webview how to jump to the new Activity




            


I would like to achieve a jump connector by clicking on the WebView to the new Activity in, instead of loading in the original Activity in my code as follows:
 
m_webView = (WebView) findViewById (R.id.webview);
Intent intent = getIntent ();

// Set the title
String titleString = intent.getStringExtra (getString (R.string.http_title));
this.setTitle (titleString);

// Load the page
String urlString = intent.getStringExtra (getString (R.string.http_address));
m_webView.setWebChromeClient (new WebChromeClient ());
m_webView.setWebViewClient (new WebViewClient () {

/ * (Non-Javadoc)
*see Android.webkit.WebViewClient # shouldOverrideUrlLoading (android.webkit.WebView, java.lang.String)
* /
Override
public boolean shouldOverrideUrlLoading (WebView view, String url) {
Intent intent = new Intent (WebViewActivity.this, WebViewActivity.class);
intent.putExtra (getString (R.string.http_title), url);
intent.putExtra (getString (R.string.http_address), url);
startActivity (intent);
return true;
}

});

m_webView.getSettings () setJavaScriptEnabled (true);.
m_webView.loadUrl (urlString);



Roughly like this, but we encounter a problem: for example, I just started loading is http://www.google.com this site, it will automatically jump, jump to the final http://www.google. com.hk the site, but the process will be more than one Activity.

I should rewrite this function public boolean shouldOverrideUrlLoading (WebView view, String url), it does not matter is to click or automatically loaded, as long as the WebView web site should load will perform to this function, but I just want to manually click a link when it is It will jump to the new Activity. Do not know where to write functions to achieve.

The Internet to find a lot of information, some say that by setOnClickListener, but still can not distinguish whether the connection clicked, can not address the link is clicked, please enlighten me
Reply:
No sensible ah
Reply:
Your question is how to solve ah?
Reply:
 
// Rewrite shouldOverrideUrlLoading ways to make click on the link is not used after other browsers open.
Override
public boolean shouldOverrideUrlLoading (WebView view, String url) {
view.loadUrl (url);
// If you do not click on links to other processing event returns true, otherwise it returns false
return true;
}

Reply:
The landlord, how to solve your problem?

No comments:

Post a Comment