Amn*_*mna 7 java android class parse-platform android-studio
我正在为我的应用程序使用Android Studio,为我的数据库使用Parse ...在我创建的帐户页面上,它允许用户输入名字,姓氏,电子邮件,用户名和密码.
但我的代码是使用parseUser ...我不知道如何在数据库中设置名字和姓氏.我知道setUsername,setPassword,setEmail是它的一部分......但是如果你在Parse中创建一个列呢?你怎么能在课堂上添加这个?
这是我的代码的一部分,它看起来像...我的问题是在我的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) {
Run Code Online (Sandbox Code Playgroud)
mik*_*013 13
是的,Parse提供了保存用户名,密码(如setUsername(params)和setPassword(params))的方法,但是如果要向表中添加更多数据,可以根据需要创建更多列,就像我在此代码段中所做的那样.
如果您已经在名称,电话,地址,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.*/
}
}
});
Run Code Online (Sandbox Code Playgroud)
注意:第一个参数是列名,第二个是值.因此,它基本上就像一个键值对.
这是解决问题..如果这可行的话就知道了......好运.. :)