0

How to make the webChromeClient()calss's callbacks handles and listen to a button? The problem I have is that, I have a button and anedittext field, both of them are in a RelativeLayout and the webView is layed-out above them so I can avoid mixing the contents of the displayed webpage with both of the buttonand edittext. The purpose of having an edittext field is to allow the user to enter a webpage name. And the purpose of having a button is to launch the webpage the user have entered. I also use webClientView class and a toast inside the callback onPageFinished to notify me whenever the webpage finishes loading. But whenever I press the button to launch the a webpage specified in the edittext field, the callback onPageFinish is always called even BEFORE the webpage finishes loading. For an example, if I specified a website address in the edittext and pressed the button repeatedly, I will get the toast output as much as the number of pressings on the button. Please refer to my question I posted here which is almost regarding the same issue. despite it solved my problem partially, when I was coding the demands of the App, I then realized that answers on my question I referenced here are seamed and or not sufficient. Is there any way to solve that issue using the webChromeView class? and how?

JavaCode:

OnClickListener btnGoListener = new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        webView00.loadUrl(etUrl.getText().toString());
        webView00.setWebViewClient(new WebViewClient() {

            public void onPageFinished(WebView view, String url) {
                Toast.makeText(getBaseContext(), "Loading Finished 2", Toast.LENGTH_LONG)
                .show();
            }
        });
    }
};
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_web_page00);

    webView00 = (WebView) findViewById(R.id.webView00);
    btnGo = (Button) findViewById(R.id.go_btn);
    etUrl = (EditText) findViewById(R.id.url_edittext);

    webView00.getSettings().setJavaScriptEnabled(true);
    webView00.setWebChromeClient(new myWebChromeClient());

    btnGo.setOnClickListener(btnGoListener);
    webView00.loadUrl("http://google.com");
    webView00.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
            Toast.makeText(getBaseContext(), "Loading Finished 1", Toast.LENGTH_LONG)
            .show();
        }
    });

}

public class myWebChromeClient extends WebChromeClient {

}
Community
  • 1
  • 1
EDECoder
  • 59
  • 1
  • 8

1 Answers1

0

Why are you setting a new webviewclient every time the button is clicked? Just do it once.

ksasq
  • 4,424
  • 2
  • 18
  • 10
  • because I got this problem in the link:http://stackoverflow.com/questions/23155432/onpagefinished-method-is-called-before-the-website-finishes-loading – EDECoder Apr 20 '14 at 12:19