我有一个简单的helloworld应用程序.我试图告诉活动用户单击了“ Cnn.com”
WebViewClient wc = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view,String url) {
if (url.equals("http://cnn.com/")) {
//TELL ACTIVITY CNN WAS CLICKED
return true;
} else {
return false;
}
}
};
mWebView.setWebViewClient(wc);
我该怎么做.
(我来自C#.NET背景)
最佳答案
public class YourActivity extends Activity{
// bla bla bla
// the code you already have
WebViewClient wc = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view,String url) {
if (url.equals("http://cnn.com/")) {
YourActivity.this.tellMe();
return true;
} else {
return false;
}
}
};
// this is the method to 'tell' the activity that someone clicked the link
public void tellMe(){
// in this case I just raise a toast.
// but you can do whatever you want here ;)
Toast.makeText(YourActivity.this,"eyy!! somebody clicked the cnn link",1).show();
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。