Load Url in Web View
I have a small problem that I want to load a url in web view but it doesn't displayed in webview, it displayed in default Android browser. How can we resist this to open in webview and one thing more that if I will use any other web url then it simply displayed in web view. This problem with only my particular url. What is the solution for that.
My url: http://www.bizrate.com/rd?t=http%3A%2F%2Fclickfrom.buy.com%2Fdefault.asp%3Fadid%3D17865%26sURL%3Dhttp%3A%2F%2Fwww.buy.com%2Fprod%2F4x-silicone-skin-soft-gel-case-for-htc-droid-incredible%2Fq%2Floc%2F111%2F219945395.html&mid=18893&cat_id=8515&atom=8517&prod_id=2513751439&oid=2388674793&pos=1&b_id=18&bid_type=4&bamt=45e4b920dcffc474&rf=af1&af_assettype_id=10&af_creative_id=6&af_id=50087&af_placement_id=1
my code:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.storesite);
//Bundle bundle = getIntent().getExtras();
WebView web = (WebView)findViewById(R.id.web_store);
//MyWebViewClient web1 = new MyWebViewClient();
//web1.shouldOverrideUrlLoading(web, "http://www.bizrate.com/rd?t=http%3A%2F%2Fclickfrom.buy.com%2Fdefault.asp%3Fadid%3D17865%26sURL%3Dhttp%3A%2F%2Fwww.buy.com%2Fprod%2F4x-silicone-skin-soft-gel-case-for-htc-droid-incredible%2Fq%2Floc%2F111%2F219945395.html&mid=18893&cat_id=8515&atom=8517&prod_id=2513751439&oid=2388674793&pos=1&b_id=18&bid_type=4&bamt=45e4b920dcffc474&rf=af1&af_assettype_id=10&af_creative_id=6&af_id=50087&af_placement_id=1");
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("http://www.bizrate.c开发者_如何学Goom/rd?t=http%3A%2F%2Fclickfrom.buy.com%2Fdefault.asp%3Fadid%3D17865%26sURL%3Dhttp%3A%2F%2Fwww.buy.com%2Fprod%2F4x-silicone-skin-soft-gel-case-for-htc-droid-incredible%2Fq%2Floc%2F111%2F219945395.html&mid=18893&cat_id=8515&atom=8517&prod_id=2513751439&oid=2388674793&pos=1&b_id=18&bid_type=4&bamt=45e4b920dcffc474&rf=af1&af_assettype_id=10&af_creative_id=6&af_id=50087&af_placement_id=1");
}
use like this
web.loadUrl("http://www.bizrate.com/rd?t=http%3A%2F%2Fclickfrom.buy.com%2Fdefault.asp%3Fadid%3D17865%26sURL%3Dhttp%3A%2F%2Fwww.buy.com%2Fprod%2F4x-silicone-skin-soft-gel-case-for-htc-droid-incredible%2Fq%2Floc%2F111%2F219945395.html&mid=18893&cat_id=8515&atom=8517&prod_id=2513751439&oid=2388674793&pos=1&b_id=18&bid_type=4&bamt=45e4b920dcffc474&rf=af1&af_assettype_id=10&af_creative_id=6&af_id=50087&af_placement_id=1");
public class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
Try this:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// get the web view
webView = (WebView) findViewById(R.id.webview);
// prepare the web view
registerForContextMenu(webView);
webView.setWebViewClient(new ItemWebViewClient());
}
private class ItemWebViewClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// show progress bar
}
@Override
public void onPageFinished(WebView view, String url) {
// hide the progress bar
}
}
精彩评论