1

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);
}

}

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

1 Comment

That's necessary to switch the type from Textview to String. I've used something similar to this in another class (sign up) and it works, something to do with the ParseUser bit?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.