我已经在parse.com /*中创建了user类来保存用户名和密码,接下来我使用编辑按钮来添加配置文件详细信息,并将其与userid一起保存。现在的问题是如何更新相同的用户配置文件详细信息?每次创建我的新用户配置文件时。帮帮我..!谢谢
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();
}
}
});发布于 2015-08-01 14:55:21
要更新用户配置文件,首先需要检查配置文件是否存在于" profile“类中,如果存在,则需要更新该行的值;如果不存在,则意味着需要创建新的配置文件对象并保存它。
代码:
// 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
}
}
});https://stackoverflow.com/questions/31759137
复制相似问题