如何从 Parse.com 中删除整行并用新数据更新它
How to delete entire row from Parse.com and update it with new data
删除代码
DeleteDetails.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final ParseObject Details = new ParseObject("Details");
ParseUser user = ParseUser.getCurrentUser();
Details.put("User", user);
Details.remove("Age");
Details.remove("Email_Address");
Details.remove("Location");
Details.remove("FullName");
Details.saveInBackground();
}
});
我已经创建了上面的代码,它从 Parse 上的 table 中删除了数据,但是它会自动创建一个新字段。我希望能够输入数据,将其删除并再次输入。一旦用户退出应用程序并 returns ,数据将从云端获取并显示在 TextViews 中。
TextView 代码
ParseQuery<ParseObject> requestAge = ParseQuery.getQuery("Details");
requestAge.getFirstInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject reqDetails, ParseException e) {
if (reqDetails != null) {
Log.d("reqDetails", "Got it");
//Retrieve Age
String gettheAge = reqDetails.getString("Age");
EditText displayAge = (EditText)findViewById(R.id.ageET);
displayAge.setText(gettheAge);
//Retrieve E-mail address
String gettheEmail = reqDetails.getString("Email_Address");
EditText displayEmail = (EditText)findViewById(R.id.EmailET);
displayEmail.setText(gettheEmail);
//Retrieve Location:
String gettheLocation = reqDetails.getString("Location");
EditText displayLocation = (EditText)findViewById(R.id.LocationET);
displayLocation.setText(gettheLocation);
//Retrieve Name:
String gettheName = reqDetails.getString("FullName");
EditText displayName = (EditText)findViewById(R.id.NameET);
displayName.setText(gettheName);
Toast.makeText(getApplicationContext(),
"Successfully Recieved Personal Details",
Toast.LENGTH_LONG).show();
} else {
Log.d("reqAge", "Empty_query");
Toast.makeText(getApplicationContext(),
"Can't Get Details, Check Connection", Toast.LENGTH_LONG)
.show();
}
}
});
如果要在 Parse 中删除对象,只需对要删除的对象调用 deleteInBackground
方法即可。
这是一个关于如何通过 ID 删除特定行的示例:
//"Status" is the tableName in parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Status");
//"objectId" the column name in parse.com
//objectID is the content ID in the table objectId
query.whereEqualTo("objectId", objectID);
query.getFirstInBackground(new GetCallback<ParseObject>() {
@Override
public void done(ParseObject status, ParseException e) {
try {
status.delete();
status.saveInBackground();
}catch(ParseException ex){
ex.printStackTrace();
}
}
});
希望这有助于祝你好运。
删除代码
DeleteDetails.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final ParseObject Details = new ParseObject("Details");
ParseUser user = ParseUser.getCurrentUser();
Details.put("User", user);
Details.remove("Age");
Details.remove("Email_Address");
Details.remove("Location");
Details.remove("FullName");
Details.saveInBackground();
}
});
我已经创建了上面的代码,它从 Parse 上的 table 中删除了数据,但是它会自动创建一个新字段。我希望能够输入数据,将其删除并再次输入。一旦用户退出应用程序并 returns ,数据将从云端获取并显示在 TextViews 中。
TextView 代码
ParseQuery<ParseObject> requestAge = ParseQuery.getQuery("Details");
requestAge.getFirstInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject reqDetails, ParseException e) {
if (reqDetails != null) {
Log.d("reqDetails", "Got it");
//Retrieve Age
String gettheAge = reqDetails.getString("Age");
EditText displayAge = (EditText)findViewById(R.id.ageET);
displayAge.setText(gettheAge);
//Retrieve E-mail address
String gettheEmail = reqDetails.getString("Email_Address");
EditText displayEmail = (EditText)findViewById(R.id.EmailET);
displayEmail.setText(gettheEmail);
//Retrieve Location:
String gettheLocation = reqDetails.getString("Location");
EditText displayLocation = (EditText)findViewById(R.id.LocationET);
displayLocation.setText(gettheLocation);
//Retrieve Name:
String gettheName = reqDetails.getString("FullName");
EditText displayName = (EditText)findViewById(R.id.NameET);
displayName.setText(gettheName);
Toast.makeText(getApplicationContext(),
"Successfully Recieved Personal Details",
Toast.LENGTH_LONG).show();
} else {
Log.d("reqAge", "Empty_query");
Toast.makeText(getApplicationContext(),
"Can't Get Details, Check Connection", Toast.LENGTH_LONG)
.show();
}
}
});
如果要在 Parse 中删除对象,只需对要删除的对象调用 deleteInBackground
方法即可。
这是一个关于如何通过 ID 删除特定行的示例:
//"Status" is the tableName in parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Status");
//"objectId" the column name in parse.com
//objectID is the content ID in the table objectId
query.whereEqualTo("objectId", objectID);
query.getFirstInBackground(new GetCallback<ParseObject>() {
@Override
public void done(ParseObject status, ParseException e) {
try {
status.delete();
status.saveInBackground();
}catch(ParseException ex){
ex.printStackTrace();
}
}
});
希望这有助于祝你好运。