简体   繁体   English

将EditText输入从布局传递到Activity以在Android中进行数据库输入onClick

[英]passing EditText input from layout to Activity for database input onClick in android

i have several EditText inputs in my layout, 我在布局中有几个EditText输入,

<EditText
        android:id="@+id/sign_up_user_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="@string/user_name"
        android:inputType="textPersonName"
        android:singleLine="true" >

        <requestFocus />
    </EditText>

    <EditText...

i want to pass the user input into the activity and upon onClick have the user input pass to the database (i'm using parse.com). 我想将用户输入传递给活动,并在onClick上将用户输入传递给数据库(我正在使用parse.com)。

public class SignUp extends Activity{
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
            setContentView(R.layout.sign_up);
    }
    public void onClickSignUp(View view) {

        ParseUser user = new ParseUser();
        user.setUsername("document.getElementById('sign_up_user_name').value");
        user.setPassword("document.getElementById('sign_up_password').value");
        user.setEmail("document.getElementById('sign_up_email_address').value");
        user.put("gender", "document.getElementById('sign_up_select_gender').checked");
        ParseACL defaultACL = new ParseACL();
        defaultACL.setPublicReadAccess(true);
        ParseACL.setDefaultACL(defaultACL, true);

        user.signUpInBackground(new SignUpCallback() {
              public void done(ParseException e) {
                if (e == null) {...

i've followed a couple of tutorials (including the one on parse.com for user signup where they just use a static string for user information). 我遵循了一些教程(包括parse.com上用于用户注册的教程,在该教程中,他们只是使用静态字符串作为用户信息)。 i know i'm missing some element of passing EditText input into my activity and maybe even syntax errors in 我知道我缺少将EditText输入传递到我的活动中的某些元素,甚至可能缺少语法错误

user.setUsername("document.getElementById('sign_up_user_name').value");

any help would be hot. 任何帮助都会很热。 thank you. 谢谢。

There is not a lot of info that you provided. 您提供的信息很多。 If I read the above correctly, you have a WebView where the user enters information. 如果我正确阅读了上述内容,则您拥有一个WebView,用户可以在其中输入信息。 And when that info is entered, you want to capture that on the native-side of Android. 输入该信息后,您希望在Android的本机端捕获该信息。

If the above is the case, you need to use a Java/Javascript bridge. 如果是上述情况,则需要使用Java / Java桥。 On the bridge class that you will implement is where you will do the ParseUser add and puts and other related. 在将要实现的桥类上,将在其中执行ParseUser的添加和放置以及其他相关操作。

See method addJavascriptInterface at http://developer.android.com/reference/android/webkit/WebView.html . 请参见http://developer.android.com/reference/android/webkit/WebView.html上的方法addJavascriptInterface Also do a search for this here on Stackoverflow or Google it; 也可以在Stackoverflow或Google上对此进行搜索; there are lots of examples. 有很多例子。

CEO 首席执行官

To get the text out of an EditText try this: 要从EditText中获取文本,请尝试以下操作:

EditText et = (EditText) findViewById(R.id.sign_up_user_name);
String s = et.getText();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM