yuva ツ
yuva ツ

Reputation: 3703

Handle onclick function of html webview in android

I'm trying to handled onclick of html in android.refered enter link description here but its not detecting.

<script language="javascript">

   function GreenClicked()
   {
      valid.performClick();
      document.getElementById("Green").value = "J'accepte";
   }
</script>

html tag inside body-

 <div  id="Green" onclick="GreenClicked()">Green<span></span></div>

java code -

mGreenPassenger= new Button(getActivity());
        mGreenPassenger.setOnClickListener(this);

        WebSettings ws = mWebView.getSettings();
        ws.setJavaScriptEnabled(true);
        // Add the interface to record javascript events
        mWebView.addJavascriptInterface(mGreenPassenger, "Green");

Upvotes: 2

Views: 2496

Answers (1)

CodingIntrigue
CodingIntrigue

Reputation: 78585

The pitfalls of copying code from StackOverflow is that you might not understand it fully.

function GreenClicked()
{
    Green.performClick(); // Needs to be your JS Interface name
    document.getElementById("Green").value = "J'accepte";
}

The Android docs on this are great. Use them. You'll have more of an understanding of what's going on in your own code.

Upvotes: 4

Related Questions