0

I have a webview in my activity and i am displaying a form in this webview. I want to finish the activity when user clicks on the Submit button of the form. How can i do this.

Or in Another way you can say that i want to get the id of the button when users click on that in java and perform the finish Activity method.

I have gone through this link

Detect click on HTML button through javascript in Android WebView

Thank for considering..

Community
  • 1
  • 1
user3154663
  • 291
  • 1
  • 2
  • 18

2 Answers2

0

You can pass the parameter into java script handler method to solve ur second option.

    <button type="button" onclick="jshandler.onClick('HEllo');">OK</button>

And retrieve from the method.

    @JavascriptInterface
    public void onClick(String id) {
        Log.i("JsHandler onClick", id);
    }

u can find the complete tutorial here

user1156041
  • 2,155
  • 5
  • 24
  • 54
0

Take a look at WebViewClient's methods. Some of them might be appropriate for you. For example if the submit button loads another page and you know it's url, you can listen for it's loading in onPageStarted or onPageFinished. I am not sure whether these methods will work for you but at least you can search for WebViewClient solutions of a similar problem.

stan0
  • 11,549
  • 6
  • 42
  • 59