Android - simple user input form web-view to back-end java with jQuery Mobile

前端 未结 1 1850
渐次进展
渐次进展 2021-01-03 04:17

I am currently designing a native android application. I am planning to use jQuery Mobile web view as my interface and do all the calculations with java back-end. (still dec

相关标签:
1条回答
  • 2021-01-03 05:02

    OK, here's an example of interacting with the javascript interface...

    Setting the javascript interface in your Activity...

    JavascriptInterface javasriptInterface = new JavascriptInterface(this);
    webview.addJavascriptInterface(javasriptInterface, "Android");
    

    The inner JavascriptInterface class in your Android Activity...

    public class JavascriptInterface {
        Context mContext;
    
        JavascriptInterface(Context c) {
            mContext = c;
        }
    
        public boolean doSomething(String name, String address) {
            ...
            return true;
        }
    }
    

    EDIT: Your form will have various input fields. Example...

    <form name="myForm" ...>
        <input type=text name=personName>
        <input type=text name=personAddress>
        <input type="button" value="Do it" onClick="callDoSomething()" />
    </form>
    
    <script type="text/javascript">
        function callDoSomething() {
            var theName = document.myForm.personName.value;
            var theAddress = document.myForm.personAddress.value;
            var result = Android.doSomething(theName, theAddress);
        }
    </script>
    
    0 讨论(0)
提交回复
热议问题