WebView through setContentView

1

Hello people, I come all day wanting to solve this. I have a Main activity that has a WebView. This activity is attentive to the connection to the internet. When you do not have an Internet connection, you will be set up with a new Layout containing a button, to re-try to connect again.

Change Layout using setContentView (R.layout.sin_conexion);

When re-trying to connect from the button of that layout. The WebView remains blank. The Toast responds and I do not know how to make the WebView show me again like when I open the APP. Please someone to give me any suggestions, ideas, anything?

Thank you very much in advance.

 public void intento (View view){

        Toast.makeText(Web.this, "REINTENTANDO", Toast.LENGTH_LONG).show();
        setContentView(R.layout.activity_web_view);
        web.setWebViewClient(new MyWebViewClient());
        WebSettings settings = web.getSettings();
        settings.setJavaScriptEnabled(true);
        web.loadUrl(url);
     }

    private class MyWebViewClient extends WebViewClient {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }
    
asked by Jonatan Paez 21.11.2018 в 04:10
source

1 answer

1

When reloading the new layout you should get the reference of the view again, in this case the WebView in the layout after calling setContentView() .

 public void intento (View view){

        Toast.makeText(Web.this, "REINTENTANDO", Toast.LENGTH_LONG).show();
        setContentView(R.layout.activity_web_view);

        //* obten la referencia del WebView
        web = (WebView)findViewById(R.id.<id WebView>);

        web.setWebViewClient(new MyWebViewClient());
        WebSettings settings = web.getSettings();
        settings.setJavaScriptEnabled(true);
        web.loadUrl(url);
     }
    
answered by 21.11.2018 / 04:55
source