使用Parse,Android更新用户详细信息

时间:2014-12-06 19:40:35

标签: android parse-platform

不确定我在哪里出错了。我有一个用户表(Parse.com后端),以及一个允许用户更新字段的表单,以获取用户详细信息。当我按下更新按钮时,意图有效,但没有更新任何细节。

 @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 个答案:

答案 0 :(得分:1)

看起来您没有从输入字段中读取新值。

在更新解析用户

之前,您需要从字段中获取它们
mUsername = mUsernameField.getText().toString();
mEmail = mEmailField.getText().toString():
mLocation = mLocationField.getText().toString():
mWebsite = mWebsiteField.getText().toString();