Android的 - 简单的用户输入表单网络视图后端Java使用jQuery Mobile [英] Android - simple user input form web-view to back-end java with jQuery Mobile

查看:121
本文介绍了Android的 - 简单的用户输入表单网络视图后端Java使用jQuery Mobile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在设计一个原生的Andr​​oid应用程序。我打算使用jQuery Mobile的网络视图,我的界面,做所有的计算与Java后端。 (还没有决定使用PhoneGap的或没有)

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 deciding using phonegap or not)

我实现一个页面,允许用户填写表单和变量传递到Android Java的一部分了一些困难。

I have some difficulties implementing a page that allows a user to fill in a form and pass the variable to the android java part.

研究整个上午,我已经学会了如何与addJavascriptInterface的JavaScript / HTML和Java之间的交互()。但我唯一能找到回答我的问题是使用JSON。这似乎有点复杂。有没有一种方法,我可以通过该变量作为一个Java函数的参数?

Researching all morning, I have learned how to interact between javascript/html and java with addJavascriptInterface(). But the only thing I can find that answer my question is with JSON. That seems a little complicated. Is there a way I can pass the variable as a parameter of a java function?

(我知道,如果我不使用Web视图,我可以简单地使用gettext()或getSelectedItem()用默认的UI做什么,我想)

(I learned that if I do not use a web view, I can simply use getText() or getSelectedItem() with default UI to do what I want to)

我很抱歉,没有code avaliable,因为这仍然是在设计阶段,我有点新Android SDK中。

I apologize there is no code avaliable, since this is still in designing stage, and I am a little new to android sdk.

感谢

推荐答案

确定,这里是使用JavaScript界面​​进行交互的例子...

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

设置的JavaScript界面​​在你的活动......

Setting the javascript interface in your Activity...

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

在你的Andr​​oid活动内部JavascriptInterface类...

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;
    }
}

编辑: 您的形式将有不同的输入字段。示例...

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>

这篇关于Android的 - 简单的用户输入表单网络视图后端Java使用jQuery Mobile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆