2014-10-18 7 views
7

Używam Android Studio dla mojej aplikacji i Parse dla mojej bazy danych ... i na stronie tworzenia konta mam, to pozwala użytkownikowi wprowadzić imię, nazwisko, adres e-mail, nazwę użytkownika i hasło.Parse.com: z parseUser, jak mogę zapisać dane w kolumnie, którą utworzyłem w analizie z klasy?

Ale mój kod używa parseUser ... Nie wiem jak ustawić imię i nazwisko w bazie danych. Wiem, że setUsername, setPassword, setEmail jest częścią tego ... ale co jeśli tworzysz kolumnę w Parse? Jak dodać to do swojej klasy?

To jest część mojego kodu, jak to wygląda ... mój problem jest w rachunku innego mam:

  // 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) { 

Odpowiedz

12

Tak, analizować nie udostępniają metody zapisuje nazwy użytkownika, hasła, jak setUsername (params) i setPassword (params), ale jeśli chcesz dodać więcej danych do tabel, możesz utworzyć więcej kolumn zgodnie z własnymi potrzebami, tak jak to zrobiłem w tym fragmencie kodu.

Jeśli pojawiły się kolumny utworzone już w parsowaniu, takie jak nazwa, telefon, adres, cityState, companyId, tak to robię.

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

       } 

      } 
     }); 

UWAGA: Pierwsze params jest nazwa kolumny, a drugi jest wartością. Więc zasadniczo działa jak para wartości klucza.

to rozwiązać problem..lemme wiem czy to works..good szczęścia .. :)

+0

Dziękuję bardzo! Pomogło, poszedłem za tym, jak to zrobiłeś i udało mi się zapisać nowe kolumny! – Amna

+0

To jest niesamowite !!. Cieszę się, że mogłem pomóc .. :) – mike20132013

+0

cześć, czy możemy zmienić domyślny stół (użytkownika) na inny stół? – Nawaf

0
/** 
    * 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); 
        } 
       } 
      } 
     }); 
    } 
+0

Witaj Twój problem rozwiązany lub nie –

+0

Dziękujemy! Pomogło! Udało mi się go uruchomić! – Amna

+0

Cześć Amma, możesz poprawić moją odpowiedź. –

Powiązane problemy