I have a simple page in html:
<html>
<head>
<script >
function submit() {
alert('aa');
}
</script>
</head>
<body>
<form action = "form.html" method = "POST">
Label<inpt type = "text"></br>
Label2<inpt type = "text"></br>
Label3<inpt type = "text"></br>
Label4<inpt type = "text"></br>
Label5<inpt type = "text"></br>
<button type="button" id="no" onclick="submit();">Submit</button>
</form>
</body>
</html>
Now I want to use function submit to show AlertDialog in android. This is my code:
final MyJavaScriptInterface myJavaScriptInterface
= new MyJavaScriptInterface(this);
formWebView.addJavascriptInterface(myJavaScriptInterface, "no");
formWebView.getSettings().setJavaScriptEnabled(true);
formWebView.loadUrl(url);
formWebView.getSettings().setBuiltInZoomControls(true);
and MyJavaScriptInterface:
public class MyJavaScriptInterface {
Context mContext;
MyJavaScriptInterface(Context c) {
mContext = c;
}
public void submitForm(){
AlertDialog.Builder myDialog
= new AlertDialog.Builder(AmmsFormsWebViewActivity.this);
myDialog.setTitle("DANGER2!");
myDialog.setMessage("You can do what you want2!");
myDialog.setPositiveButton("ON", null);
myDialog.show();
}
}
but doesn't work. Where I have a bug? I want to chceck if submit() method is use from webview I want to show dialog in android.