Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am developing a Android Web Application.. I have created some code but facing one problem. Problem is that... Progress Dialog is still after loading Homepage... but when I click on page it gone... this problem with Homepage only... not inside.. If I open another link from page then working perfectly.. I have not tested on my Phone.. I have tested it on Emulator Only... and please take a look on the code... it there is any change required... please suggest.. This is my .Java file

Java
package com.aarcreationz.bhajanmala;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity 
{
    WebView mWeb;
    ProgressDialog mProgress;


    @SuppressLint("SetJavaScriptEnabled") 
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        mWeb = new WebView(this);
        mWeb.setClickable(true);
        mWeb.setFocusableInTouchMode(true);
        setContentView(mWeb);
        WebSettings settings = mWeb.getSettings();
        settings.setJavaScriptEnabled(true);


        mWeb.setWebViewClient(new WebViewClient() {
            ProgressDialog mProgress = null;

            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }


            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                mProgress = new ProgressDialog(MainActivity.this);
                mProgress.setTitle("Please Wait!");
                mProgress.setMessage("Loading...");
                mProgress.show();

            }

            public void onPageFinished(WebView view, String url) {
                if(mProgress.isShowing()) {
                    mProgress.hide();
                    mProgress.dismiss();
                }
            }
        });

        mWeb.loadUrl("http://www.aarcreationz.com/mala");
    }
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && mWeb.canGoBack())
        {
            mWeb.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}

This is my layout file

XML
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${packageName}.${activityClass}" >   
</WebView>
Posted

1 solution

Try it in your phone rather than emulator. And pick an @Override of your mWeb.setWebViewClient(new WebViewClient(){} . Hope it will work correctly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900