Issue
I have a webview and I am calling data in that wv from a webservice, and in that whole description in a webview, there is a link in the last. so, my problem is that i want to open a new activity onclick of that link only neither onclick of webview nor ontouch of webview
Solution
You need to provide an implementation for shouldOverrideUrlLoading
. You'll have to setup a WebViewClient
for your webview and inside of this method, you'll need to have some logic that recognized that link and then open the new Activity
. Something like:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView wv = (WebView) findViewById(R.id.myWebView);
wv.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(isURLMatching(url)) {
openNextActivity();
return true;
}
return super.shouldOverrideUrlLoading(view, url);
}
});
}
protected boolean isURLMatching(String url) {
// some logic to match the URL would be safe to have here
return true;
}
protected void openNextActivity() {
Intent intent = new Intent(this, MyNextActivity.class);
startActivity(intent);
}
Answered By - gunar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.