首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在android parse.com中更新用户资料

如何在android parse.com中更新用户资料
EN

Stack Overflow用户
提问于 2015-08-01 14:46:22
回答 1查看 551关注 0票数 0

我已经在parse.com /*中创建了user类来保存用户名和密码,接下来我使用编辑按钮来添加配置文件详细信息,并将其与userid一起保存。现在的问题是如何更新相同的用户配置文件详细信息?每次创建我的新用户配置文件时。帮帮我..!谢谢

代码语言:javascript
运行
复制
    profileSave.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            countryname=country.getText().toString();
            parentname=parent.getText().toString();
            childname=child.getText().toString();
            relationname=relation.getText().toString();

            if(countryname.isEmpty() || parentname.isEmpty() ||childname.isEmpty() ||relationname.isEmpty()){
                AlertDialog.Builder builder =new AlertDialog.Builder(MyProfile.this);
                builder.setTitle("Error")
                        .setMessage("please fill all the fields")
                        .setPositiveButton(android.R.string.ok,null);
                AlertDialog dialog =builder.create();
                dialog.show();

            }else{
                pDialog =new ProgressDialog(MyProfile.this);
                pDialog.setMessage("Saving..!!");
                pDialog.setIndeterminate(true);
                pDialog.show();

                //get current user
                ParseUser parseUser =ParseUser.getCurrentUser();
                String userid =parseUser.getObjectId();

                //save data in profile class
                ParseObject mProfile =new ParseObject("Profile");

                mProfile.put("country",countryname);
                mProfile.put("parent",parentname);
                mProfile.put("child",childname);
                mProfile.put("relation",relationname);
                mProfile.put("userid", userid);
                mProfile.saveInBackground();


                Intent i =new Intent(getApplicationContext(),Home.class);
                startActivity(i);
                pDialog.dismiss();

            }

        }
    });
EN

回答 1

Stack Overflow用户

发布于 2015-08-01 14:55:21

要更新用户配置文件,首先需要检查配置文件是否存在于" profile“类中,如果存在,则需要更新该行的值;如果不存在,则意味着需要创建新的配置文件对象并保存它。

代码:

代码语言:javascript
运行
复制
 // current user query

    ParseQuery<ParseUser> query= ParseUser.getQuery();
    userId= ParseUser.getCurrentUser().getObjectId();
    query.whereEqualTo("objectId", userId);

// Profile user query
    ParseQuery<ParseObject> fetchchQuery = new ParseQuery<ParseObject>("Profile");
    fetchQuery.whereMatchesQuery("userid",query);
    fetchQuery.findObjectsInBackground(new FindCallback<ParseObject>() {

            @Override
            public void done(List<ParseObject> objects, ParseException exception)  {

                if(exception == null){
                ParseObject mProfile =new ParseObject("Profile");

                 if(objects.size() > 0){
                 mProfile = objects.get(0);
                }
                mProfile.put("country",countryname);
                mProfile.put("parent",parentname);
                mProfile.put("child",childname);
                mProfile.put("relation",relationname);
                mProfile.put("userid", userid);
                mProfile.saveInBackground();

                }else{
                // error while fetching 
               }


            }
        });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31759137

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档