试图显示在Web视图网址 [英] Trying to display url in Web View

查看:212
本文介绍了试图显示在Web视图网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与循环J包试验。我试图做一个HTTP请求到一个网站,并显示web视图的网站。

我成功地得到一个结果返回,但网页视图不显示所希望的页面,而不是镀铬打开并显示页面。

我缺少的东西,还是有办法可以覆盖这个不必要的行为?

下面是我的onCreate方法,我想提出的要求:

 公共类MainActivity延伸活动{按钮connectBtn;
TextView的状态;
的WebView显示;
字符串URL =htt​​p://www.google.com
AsyncHttpClient客户端;@覆盖
保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);    状态=(的TextView)findViewById(R.id.statusbox);
    connectBtn =(按钮)findViewById(R.id.connectBtn);
    显示=(的WebView)findViewById(R.id.webView1);    connectBtn.setOnClickListener(新View.OnClickListener(){
        @覆盖
        公共无效的onClick(视图v){
            客户端=新AsyncHttpClient();
            client.get(网址,新AsyncHtt presponseHandler(){                @覆盖
                公共无效的onSuccess(字符串响应){
                    Toast.makeText(getApplicationContext(),成功!,Toast.LENGTH_SHORT).show();
                    display.loadUrl(URL);                }
            });
        }
    });
}


解决方案

setWebViewClient 你的的WebView 并重写 shouldOverrideUrlLoading()写信 view.loadUrl(URL); 该方法

只需添加这code,

  display.setWebViewClient(新WebViewClient(){
公共布尔shouldOverrideUrlLoading(的WebView视图,字符串URL){
          view.loadUrl(URL);
          返回true;
}});

I am experimenting with the loopj package. I am trying to make a HTTP request to a website and display the website in the webview.

I am successfully getting a result back, however the web view does not display the page as desired, instead chrome opens up and displays the page.

Am I missing something or is there a way I can override this unwanted behaviour?

Below is my oncreate method where I am making the request:

public class MainActivity extends Activity {

Button connectBtn;
TextView status;
WebView display;
String url = "http://www.google.com";
AsyncHttpClient client;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    status = (TextView)findViewById(R.id.statusbox);
    connectBtn = (Button)findViewById(R.id.connectBtn);
    display = (WebView)findViewById(R.id.webView1);

    connectBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            client = new AsyncHttpClient();
            client.get(url, new AsyncHttpResponseHandler(){

                @Override
                public void onSuccess(String response) {
                    Toast.makeText(getApplicationContext(), "Success!", Toast.LENGTH_SHORT).show();
                    display.loadUrl(url);

                }
            });
        }
    });
}

解决方案

setWebViewClient to your WebView and override shouldOverrideUrlLoading() now write view.loadUrl(url); in that method.

Just add this code,

display.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
          view.loadUrl(url);
          return true;
}}); 

这篇关于试图显示在Web视图网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆