Asked  6 Months ago    Answers:  5   Viewed   29 times

I have a WebView that is loading a page from the Internet. I want to show a ProgressBar until the loading is complete.

How do I listen for the completion of page loading of a WebView?



Extend WebViewClient and call onPageFinished() as follows:

mWebView.setWebViewClient(new WebViewClient() {

   public void onPageFinished(WebView view, String url) {
        // do your stuff here
Tuesday, June 1, 2021
answered 6 Months ago

The framework itself does not provide this for you (as far as I know). Translating true/false into yes/no does not strike me as more common than other potential translations (such as on/off, checked/unchecked, read-only/read-write or whatever).

I imagine that the easiest way to encapsulate the behavior is to make an extension method that wraps the construct that you suggest yourself in your question:

public static class BooleanExtensions
    public static string ToYesNoString(this bool value)
        return value ? Resources.Yes : Resources.No;


bool someValue = GetSomeValue();
Friday, June 11, 2021
answered 6 Months ago

After visiting the above links, I come up with this code and hope this helps.

wv.setWebChromeClient(new WebChromeClient() {
    public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, android.os.Message resultMsg)
        WebView.HitTestResult result = view.getHitTestResult();
        String data = result.getExtra();
        Context context = view.getContext();
        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(data));
        return false;
Wednesday, June 23, 2021
answered 6 Months ago

Don't include the method body in the class body. Write both classes, and after both classes are complete, write the method implementations:

class Y;
class X {
  void Connect(Y* Y_in);
class Y {
  void Connect(X* X_in);
inline void X::Connect(Y* Y_in) {
  pY = Y_in;
inline void Y::Connect(X* X_in) {
  pX = X_in;

That way, full information about how the objects of the class will be layed out in memory is available by the time the Connect method is implemented. And as a method in the class body and a method declared inline will both be inlined the same way, performance will be the same as well.

The only downside is that you won't be able to split these two classes over two headers in a reasonable way.

Wednesday, July 28, 2021
answered 4 Months ago

In onPageFinished():

            + "var FunctionOne = function () {"
            + "  var r = $.Deferred();"
            + "  try{document.getElementsByClassName('header')[0].style.display='none';}catch(e){}"
            + "  try{document.getElementById('section_0').style.display='none';}catch(e){}"
            + "  try{document.getElementById('page-actions').style.display='none';}catch(e){}"
            + "  try{document.getElementsByClassName('languageSelector')[0].style.display='none';}catch(e){}"
            + "  try{document.getElementById('mw-mf-last-modified').style.display='none';}catch(e){}"
            + "  try{document.getElementById('footer').style.display='none';}catch(e){}"
            + "  setTimeout(function () {"
            + "    r.resolve();"
            + "  }, 2500);"
            + "  return r;"
            + "};"
            + "var FunctionTwo = function () {"
            + "  window.CallToAnAndroidFunction.setVisible();"
            + "};"
            + "FunctionOne().done(FunctionTwo);");

In MainActivity.onCreate():

this.webView.addJavascriptInterface(new JsObject(webView, loadingView), "CallToAnAndroidFunction");

In MainActivity():

public class JsObject {
    private View loadingView;
    private View view;
    JsObject(View view, View loadingView){this.view = view;this.loadingView = loadingView;}
    public void setVisible(){
        runOnUiThread(new Runnable() {

           public void run() {

So, it was a combination of making a JavascriptInterface and making a JS function to wait for the JS calls to finish before calling the interface (with the visibility settings).

Wednesday, September 8, 2021
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :