简体   繁体   中英

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

i have several EditText inputs in my layout,

<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).

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). i know i'm missing some element of passing EditText input into my activity and maybe even syntax errors in

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. And when that info is entered, you want to capture that on the native-side of Android.

If the above is the case, you need to use a Java/Javascript bridge. On the bridge class that you will implement is where you will do the ParseUser add and puts and other related.

See method addJavascriptInterface at http://developer.android.com/reference/android/webkit/WebView.html . Also do a search for this here on Stackoverflow or Google it; there are lots of examples.

CEO

To get the text out of an EditText try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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