title: Webview's Html button click detection in Activity
body: <p>I was trying to detect the HTML button click of webview into java code(In activity). I wrote my code after rferencing <a href="https://stackoverflow.com/questions/4065312/detect-click-on-html-button-through-javascript-in-android-webview/7380446#7380446">Detect click on HTML button through javascript in Android WebView</a> but is not working.</p>
  <p>My code:</p>
  <p><strong>index.html</strong></p>
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;script language=&quot;javascript&quot;&gt;
              function js1() {
                  document.loginform.method=&quot;post&quot;;
                  document.loginform.action = &quot;https://example.com/chechlogin.asp&quot;;
              }
          &lt;/script&gt;  
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form name=&quot;loginform&quot;&gt;
              &lt;input type=&quot;text&quot; name=&quot;empcode&quot; value=&quot;58686&quot; /&gt;&lt;br/&gt;
              &lt;input type=&quot;password&quot; name=&quot;emppassNTL&quot; /&gt;
              &lt;input type=&quot;submit&quot; name=&quot;submit&quot; id=&quot;submit_id&quot; onclick=&quot;login.performClick();&quot; /&gt;    
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p><strong>MainActivity.java</strong></p>
  <pre><code>package com.example.webview;
  
  import android.os.Bundle;
  import android.annotation.SuppressLint;
  import android.app.Activity;
  import android.util.Log;
  import android.view.Menu;
  import android.view.View;
  import android.view.Window;
  import android.webkit.JavascriptInterface;
  import android.webkit.WebSettings;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  import android.widget.EditText;
  import android.widget.TextView;
  import android.widget.Toast;
  
  @SuppressLint(&quot;SetJavaScriptEnabled&quot;)
  public class MainActivity extends Activity {
  
     private EditText field;
     private WebView browser;
  
     @Override        
     protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        field = (EditText)findViewById(R.id.urlField);
        browser = (WebView)findViewById(R.id.webView1);
        browser.getSettings().setJavaScriptEnabled(true);
        browser.setWebViewClient(new MyBrowser());
        browser.loadUrl(&quot;file:///android_asset/index.html&quot;);
     }
  
  
     @SuppressLint(&quot;JavascriptInterface&quot;)
     public void open(View view){
        String url = field.getText().toString();
        browser.getSettings().setLoadsImagesAutomatically(true);
        browser.getSettings().setJavaScriptEnabled(true);
        browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        browser.loadUrl(url);
        browser.addJavascriptInterface(new Object()
        {
            @JavascriptInterface
          public void performClick()
          {
              Log.d(&quot;LOGIN::&quot;, &quot;Clicked&quot;);
               Toast.makeText(MainActivity.this, &quot;Login clicked&quot;, Toast.LENGTH_LONG).show();
          }
        }, &quot;login&quot;);
  
     }
     private class MyBrowser extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
           view.loadUrl(url);
           return true;
        }
     }
  
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
     }
  
  }  
  </code></pre>
  <p>But the performClick() method is not being called.</p>
  <p>How can I correct this error?</p>