1

I am using the following code to hide the webview if a url ends with a particular string.

 webview.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageFinished(WebView view, String url) {
        if (url.endsWith("index.asp")) {
             Toast.makeText(getActivity().getApplicationContext(),"Login successfull",Toast.LENGTH_LONG).show();
            webview.setVisibility(view.GONE);
        }
    }
 });

but the webview still remains if the url ends with index.asp( for example "http://abc.def/index.asp")

toadalskiii
  • 136
  • 2
  • 14

4 Answers4

3

instead of:

webview.setVisibility(view.GONE);

use:

view.setVisibility(view.GONE);
hrskrs
  • 4,447
  • 5
  • 38
  • 52
  • Maybe if you post more code we can help you, otherwise a bad solution can be to wrap `WebView` in a `FrameView` and if it satisfies your condition show that `frameview` othervise hide it`(Visibility.GONE)` – hrskrs Sep 02 '15 at 06:02
0

As discussed here How to listen for a Webview finishing loading a URL in Android? sometimes webview url will redirect the call backs. it means onPageFinished() will call several times (more than one time). If it is the case you should check the redirect states aswell for your url call backs in onPageFinished() method

boolean loadingFinished = true;
boolean redirect = false;

mWebView.setWebViewClient(new WebViewClient() {

   @Override
   public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) {
       if (!loadingFinished) {
          redirect = true;
       }

   loadingFinished = false;
   view.loadUrl(urlNewString);
   return true;
   }

   @Override
   public void onPageStarted(WebView view, String url, Bitmap facIcon) {
        loadingFinished = false;
        //SHOW LOADING IF IT ISNT ALREADY VISIBLE  
    }

   @Override
   public void onPageFinished(WebView view, String url) {
       if(!redirect){
          loadingFinished = true;
       }

       if(loadingFinished && !redirect){
         //HIDE LOADING IT HAS FINISHED
                 if (url.endsWith("index.asp")) {
                    webview.setVisibility(view.GONE);
                  }

       } else{
          redirect = false; 
       }

    }
});

Hope it will helps

Community
  • 1
  • 1
King of Masses
  • 18,405
  • 4
  • 60
  • 77
0

Try to use the other library if you do not want to draw the content on a view. For instane, jsoup library.

Vyacheslav
  • 26,359
  • 19
  • 112
  • 194
0

Can you check by clearing animation if you have set any since i had same problem with layout not disappearing on setVisibility(View.Gone).. Try this

webview.clearAnimation(); 

it helped me.

Awais Tariq
  • 7,724
  • 5
  • 31
  • 54
Isham
  • 424
  • 4
  • 14