/** * Clear a view. Applies to ImageView, WebView, and TextView. * * @return self */ public T clear(){ if(view != null){ if(view instanceof ImageView){ ImageView iv = ((ImageView) view); iv.setImageBitmap(null); iv.setTag(AQuery.TAG_URL, null); }else if(view instanceof WebView){ WebView wv = ((WebView) view); wv.stopLoading(); wv.clearView(); wv.setTag(AQuery.TAG_URL, null); }else if(view instanceof TextView){ TextView tv = ((TextView) view); tv.setText(""); } } return self(); }
@Test public void shouldRecordClearView() { assertThat(shadowOf(webView).wasClearViewCalled()).isFalse(); webView.clearView(); assertThat(shadowOf(webView).wasClearViewCalled()).isTrue(); }
@Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { view.clearView(); }
@Override public Object callback(Object obj1, Object obj2) { int pos = (int)obj2; if (0 == pos) { mWebView.clearView(); } else { mWebView.loadUrl("https://apps4av.net/ads/" + pos + ".php"); } return null; } });
private ViewGroup mScrollView //linearlayout encapsuled in a scrollView; private WebView mWebView; private Handler mHandler = new Handler(){ public void handleMessage(Message msg){ mWebView.reload(); mScrollView.addView(mWebView, 0); } }; private updateWebView(){ //update the content of your web view mScrollView.removeView(mWebView); mWebView.clearView(); mHandler.sendMessageDelayed(mHandler.obtainMessage(0), 200); }
if (urlPath .compareToIgnoreCase(Const.defURL) == 0) { } else { mWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.clearView(); view.loadUrl(url); return true; } }); }
final WebView wbView = (WebView) findViewById(R.id.WebView); wbView.getSettings().setJavaScriptEnabled(true); wbView.loadUrl("https://play.google.com/store/apps"); wbView.clearView(); wbView.measure(100, 100); wbView.getSettings().setUseWideViewPort(true); wbView.getSettings().setLoadWithOverviewMode(true);
WebView img = (WebView) findViewById(R.id.webview); img.clearView(); img.clearCache(true); img.getSettings().setBuiltInZoomControls(true); img.getSettings().setSupportZoom(false); img.loadUrl(image);
public void refresh() { mWebView.clearView(); mWebView.loadUrl("about:blank"); mWebView.stopLoading(); String url = buildOAuthUrl(); mWebView.loadUrl(url); DevLog.printLog("OAUTH_ACTIVITY-refresh:", "" + url); }
/** * Clear a view. Applies to ImageView, WebView, and TextView. * * @return self */ public T clear(){ if(view != null){ if(view instanceof ImageView){ ImageView iv = ((ImageView) view); iv.setImageBitmap(null); iv.setTag(AQuery.TAG_URL, null); }else if(view instanceof WebView){ WebView wv = ((WebView) view); wv.stopLoading(); wv.clearView(); wv.setTag(AQuery.TAG_URL, null); }else if(view instanceof TextView){ TextView tv = ((TextView) view); tv.setText(""); } } return self(); }
@Override public void onReceivedError(WebView webView, int errorCode, String description, String failingUrl) { //Clearing the WebView try { webView.stopLoading(); } catch (Exception e) { } try { webView.clearView(); } catch (Exception e) { } if (webView.canGoBack()) { webView.goBack(); } webView.loadUrl("about:blank"); //Showing and creating an alet dialog AlertDialog alertDialog = new AlertDialog.Builder(youractivity.this).create(); alertDialog.setTitle("Error"); alertDialog.setMessage("No internet connection was found!"); alertDialog.setButton("Again", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); startActivity(getIntent()); } }); alertDialog.show(); //Don't forget to call supper! super.onReceivedError(webView, errorCode, description, failingUrl); }
protected void onPostExecute(String S) { mWebView.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view, int errCode, String errDescription, String failingUrl ) { try { view.stopLoading(); } catch(Exception e){} view.clearView(); Toast.makeText(getApplicationContext(), "Error code is "+errCode, Toast.LENGTH_SHORT).show(); if(errCode == -2 || errCode == -8) { view.loadData("There seems to be a problem with your Internet connection. Please try later", "text/html", "UTF-8"); } if(errCode == -14) { view.loadData("Page cannot be found on server", "text/html", "UTF-8"); } } }); mWebView.loadUrl(url); ShowProgress.dismiss(); }