简体   繁体   English

Parse.com:使用parseUser,如何在我从类中解析创建的列中保存数据?

[英]Parse.com: with parseUser, how can I save data in a column I created in parse from the class?

I am using Android Studio for my app and Parse for my database... and on the create an account page I have, it allows the user to enter in first name, last name, email, username, and password. 我正在为我的应用程序使用Android Studio,为我的数据库使用Parse ...在我创建的帐户页面上,它允许用户输入名字,姓氏,电子邮件,用户名和密码。

But my code is using parseUser... I don't know how to set the first and last name in the database. 但我的代码是使用parseUser ...我不知道如何在数据库中设置名字和姓氏。 I know setUsername, setPassword, setEmail is a part of it... but what about if you make a column in Parse? 我知道setUsername,setPassword,setEmail是它的一部分......但是如果你在Parse中创建一个列呢? How can you add this in your class? 你怎么能在课堂上添加这个?

This is a part of my code, what it looks like...my problem is in the else statement I have: 这是我的代码的一部分,它看起来像...我的问题是在我的else语句中:

          // Force user to fill up the form
            if (usernametxt.equals("") && passwordtxt.equals("") && emailtxt.equals("")) {
                Toast.makeText(getApplicationContext(),
                        "Please fill in the username, password, and email fields.",
                        Toast.LENGTH_LONG).show();

            } else {
                // Save new user data into Parse.com Data Storage
                ParseUser user = new ParseUser();

                //somehow save first and last name 

                user.setEmail(emailtxt);
                user.setUsername(usernametxt);
                user.setPassword(passwordtxt);
                user.signUpInBackground(new SignUpCallback() {
                    public void done(ParseException e) {
                        if (e == null) {

Yes, Parse does provide methods to save username, passwords like setUsername(params) and setPassword(params) but if you want to add more data to the tables, you can create more columns according to your needs as I did in this code snippet. 是的,Parse提供了保存用户名,密码(如setUsername(params)setPassword(params))的方法,但是如果要向表中添加更多数据,可以根据需要创建更多列,就像我在此代码段中所做的那样。

If you have come columns created already in parse back-end like name, phone,address,cityState,companyId, this is how I am doing it. 如果您已经在名称,电话,地址,cityState,companyId等解析后端创建了列,那么我就是这样做的。

private void savetoParse() {

        ParseUser user = new ParseUser();
        user.setUsername(usernameEditText.getText().toString());
        user.setPassword(passEditText.getText().toString());
        user.put("name", nameEditText.getText().toString());
        user.setEmail(emailEditText.getText().toString());
        user.put("phone", phoneNoEditText.getText().toString());
        user.put("address", addressEditText.getText().toString());
        user.put("cityState", cityStateEditText.getText().toString());
        user.put("companyID", compSchoolIdEditText.getText().toString());

        user.signUpInBackground(new SignUpCallback() {

            @Override
            public void done(ParseException e) {

                if (e != null) {

                    Toast.makeText(SignupActivityUpdate.this,
                            "Saving user failed.", Toast.LENGTH_SHORT).show();
                    Log.w(TAG,
                            "Error : " + e.getMessage() + ":::" + e.getCode());

                    if (e.getCode() == 202) {

                        Toast.makeText(
                                SignupActivityUpdate.this,
                                "Username already taken. \n Please choose another username.",
                                Toast.LENGTH_LONG).show();
                        usernameEditText.setText("");
                        passEditText.setText("");
                        confirmPassEditText.setText("");

                    }

                } else {

                    Toast.makeText(SignupActivityUpdate.this, "User Saved",
                            Toast.LENGTH_SHORT).show();

                    /*Do some things here if you want to.*/

                }

            }
        });

NOTE : The first params is the column name and second is the value. 注意:第一个参数是列名,第二个是值。 So, it basically acts like a key value pair. 因此,它基本上就像一个键值对。

This is solve the problem..lemme know if this works..good luck..:) 这是解决问题..如果这可行的话就知道了......好运.. :)

/**
     * user Registration here
     * save user registration value on server here
     */
    private void userRegistration()
    {
        progressDialog=new ProgressDialog(SignUpThirdPage.this);
        progressDialog.setMessage("Please Wait......");
        progressDialog.setCancelable(false);
        progressDialog.show();

        ParseUser user = new ParseUser();


        user.setUsername("Name");   
        user.setPassword(strPassword);
        user.setEmail(strEmailId);
        // surName column create on parse.com db you can check after run that code
        // like that u can add more column in signup table
         user.put("surName","Kumar");

        user.signUpInBackground(new SignUpCallback() {
            @Override
            public void done(com.parse.ParseException e) {
                // TODO Auto-generated method stub
                if (e == null) {


                    }

                } else {
                    // Sign up didn't succeed. Look at the ParseException
                    // to figure out what went wrong
                    e.printStackTrace();
                    progressDialog.dismiss();
                    if(e.getMessage().contains("already taken")){
                        alertDialog("", "you've already sign up , lets login in ", SignUpThirdPage.this, false);    
                    }
                    else if(e.getMessage().contains("has already been taken")){
                        alertDialog("", "you've already sign up , lets login in ", SignUpThirdPage.this, false);    
                    }
                    else {
                        AppConstants.showAlertDialog("", e.getMessage(), SignUpThirdPage.this, false);
                    }
                }
            }
        });
    }

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

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