Reputation: 136
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")
Upvotes: 1
Views: 1156
Reputation: 434
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.
Upvotes: 0
Reputation: 18775
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
Upvotes: 0
Reputation: 4490
instead of:
webview.setVisibility(view.GONE);
use:
view.setVisibility(view.GONE);
Upvotes: 3
Reputation: 27221
Try to use the other library if you do not want to draw the content on a view. For instane, jsoup library.
Upvotes: 0