简体   繁体   中英

Update user details using Parse, Android

Not sure where I'm going wrong this. I have a table of users (Parse.com backend), and a form that allows the user to update the fields, for their user details. When I press the Update Button, the intent works, however the none of the details are updated.

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_manage_account);

    ParseUser currentUser = ParseUser.getCurrentUser();
    userId = currentUser.getObjectId();
    mUsername = currentUser.getUsername();
    mEmail = currentUser.getEmail();
    mWebsite = currentUser.get("website").toString();
    mLocation = currentUser.get("location").toString();

    mUsernameField = (EditText)findViewById(R.id.usernameField);
    mLocationField = (EditText)findViewById(R.id.locationField);
    mEmailField = (EditText)findViewById(R.id.emailField);
    mWebsiteField = (EditText)findViewById(R.id.websiteField);

    mUsernameField.setText(mUsername);
    mLocationField.setText(mLocation);
    mEmailField.setText(mEmail);
    mWebsiteField.setText(mWebsite);

    mButton = (Button)findViewById(R.id.updateButton);


            mButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (username.isEmpty() || email.isEmpty() ||
                            location.isEmpty()){
                        AlertDialog.Builder builder = new AlertDialog.Builder(ManageAccountActivity.this);
                        builder.setMessage(R.string.sign_up_error_message)
                                .setTitle(R.string.sign_up_error_title)
                                .setPositiveButton(android.R.string.ok, null);
                        AlertDialog dialog = builder.create();
                        dialog.show();

                    }

                    else {


                        setProgressBarIndeterminateVisibility(true);

                        //Update user
                        ParseUser user = ParseUser.getCurrentUser();
                        user.setUsername(mUsername);
                        user.setEmail(mEmail);
                        user.put("location", mLocation);
                        user.put("website", mWebsite);

                        user.saveInBackground(new SaveCallback() {

                            @Override
                            public void done(ParseException e) {
                                setProgressBarIndeterminateVisibility(false);

                                if (e == null) {
                                    //Success!
                                    Intent intent = new Intent(ManageAccountActivity.this, MainActivity.class);

                                    startActivity(intent);

                                } else {
                                    AlertDialog.Builder builder = new AlertDialog.Builder(ManageAccountActivity.this);
                                    builder.setMessage(e.getMessage())
                                            .setTitle(R.string.sign_up_error_title)
                                            .setPositiveButton(android.R.string.ok, null);
                                    AlertDialog dialog = builder.create();
                                    dialog.show();
                                }
                            }
                        });

                    }

                }
            });
        }






@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.manage_account, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

Looks like you don't read new values from input fields.

You need to get them from fields, before update parse user

mUsername = mUsernameField.getText().toString();
mEmail = mEmailField.getText().toString():
mLocation = mLocationField.getText().toString():
mWebsite = mWebsiteField.getText().toString();

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