删除的代码
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上的表中删除了数据,但它会自动创建一个新字段。我希望能够输入数据,删除它,然后再次输入。一旦用户退出应用程序并返回应用程序,数据就会从云中提取并显示在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
方法即可。
Android分析文档
这是一个关于如何通过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();
}
}
});
跳这个有助于好运。