使用ListView时,我可以通过编写
this.adapter.delete(mYeets.get(position))
轻松从适配器中删除项。使用RecyclerView时,是否有相当的方法?还是现在只需通知适配器进行更改即可?private void deleteComment(int position) {
String currentUserObjectId = ParseUser.getCurrentUser().getObjectId();
ParseQuery<ParseObject> query = new ParseQuery<>("Yeet");
query.whereEqualTo(ParseConstants.KEY_OBJECT_ID, mYeets.get(position).getObjectId());
query.whereContains(ParseConstants.KEY_SENDER_ID, currentUserObjectId);
query.findInBackground((yeet, e) -> {
if (e == null) {
for (ParseObject yeetObject : yeet) {
if (yeetObject.getParseObject(ParseConstants.KEY_SENDER_AUTHOR_POINTER).getObjectId().equals((ParseUser.getCurrentUser().getObjectId()))) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mContext);
dialogBuilder.setTitle("Delete");
dialogBuilder.setMessage("Do you want to delete this Yeet?");
dialogBuilder.setPositiveButton("Yes", (dialog, which) -> {
// Iterate over all messages and delete them
for (ParseObject delete : yeet) {
delete.deleteInBackground();
//this.adapter.delete(mYeets.get(position));
this.adapter.notifyDataSetChanged();
Toast.makeText(mContext, "Yeet deleted", Toast.LENGTH_SHORT).show();
}
});
dialogBuilder.setNegativeButton("No", (dialog, which) -> {
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
}
}
} else {
Log.e("Error", e.getMessage());
}
});
}
delete.deleteInBackground();
会删除数据。这是否与从适配器中删除相同?还是有另一个命令?我找不到它。 - Martin Erlic