Parse.com:与parseUser,我怎么能保存在我的解析从类创建了一列数据? [英] Parse.com: with parseUser, how can I save data in a column I created in parse from the class?

查看:225
本文介绍了Parse.com:与parseUser,我怎么能保存在我的解析从类创建了一列数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Android的工作室为我的应用程序,并解析了我的数据库...和创建一个帐户页我有,它允许用户在姓,名,电子邮件,用户名和密码进入。

但我的code使用parseUser ...我不知道如何在数据库中设置的第一个和最后一个名字。 我知道setUsername,setPassword,setEmail是它的一部分......但什么,如果你做的解析一列?你怎么能在你的类中添加呢?

这是我的code的一部分,它是什么样子......我的问题是,在else语句我有:

  //强制用户填写表单
            如果(usernametxt.equals()及&安培; passwordtxt.equals()及&安培; emailtxt.equals()){
                Toast.makeText(getApplicationContext(),
                        请填写用户名,密码和电子邮件领域。
                        Toast.LENGTH_LONG).show();

            } 其他 {
                //保存新的用户数据到Parse.com数据存储
                ParseUser用户=新ParseUser();

                //莫名其妙地保存姓氏和名字

                user.setEmail(emailtxt);
                user.setUsername(usernametxt);
                user.setPassword(passwordtxt);
                user.signUpInBackground(新SignUpCallback(){
                    公共无效完成(ParseException的E){
                        如果(E == NULL){
 

解决方案

是的,解析确实提供了一些方法来保存的用户名,例如 setUsername(PARAMS)密码 setPassword(PARAMS)但是,如果你想添加更多的数据表,你可以根据自己的需要创建多个列,因为我在这个code段做到了。

如果你也来已在解析后端,如姓名,电话,地址创建的列,cityState,companyId,这是我怎么做的吧。

 私人无效savetoParse(){

        ParseUser用户=新ParseUser();
        user.setUsername(usernameEditText.getText()的toString());
        user.setPassword(passEditText.getText()的toString());
        user.put(姓名,nameEditText.getText()的toString());
        user.setEmail(emailEditText.getText()的toString());
        user.put(手机,phoneNoEditText.getText()的toString());
        user.put(地址,addressEditText.getText()的toString());
        user.put(cityState,cityStateEditText.getText()的toString());
        user.put(companyID,compSchoolIdEditText.getText()的toString());

        user.signUpInBackground(新SignUpCallback(){

            @覆盖
            公共无效完成(ParseException的E){

                如果(E!= NULL){

                    Toast.makeText(SignupActivityUpdate.this,
                            保存用户失败。,Toast.LENGTH_SHORT).show();
                    Log.w(TAG,
                            错误:+ e.getMessage()+:::+ e.get code());

                    如果(e.get code()== 202){

                        Toast.makeText(
                                SignupActivityUpdate.this,
                                用户名已被使用。\ n请选择其他用户名。
                                Toast.LENGTH_LONG).show();
                        usernameEditText.setText();
                        passEditText.setText();
                        confirmPassEditText.setText();

                    }

                } 其他 {

                    Toast.makeText(SignupActivityUpdate.this,用户保存,
                            Toast.LENGTH_SHORT).show();

                    / *做一些东西在这里,如果你想。* /

                }

            }
        });
 

注意:第一params为列名,第二个是值。因此,它基本上就像一个键值对。

这是解决problem..lemme知道这works..good运气..:)

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.

But my code is using parseUser... I don't know how to set the first and last name in the database. I know setUsername, setPassword, setEmail is a part of it... but what about if you make a column in 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:

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

If you have come columns created already in parse back-end like name, phone,address,cityState,companyId, this is how I am doing it.

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

这篇关于Parse.com:与parseUser,我怎么能保存在我的解析从类创建了一列数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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