我正在使用Parse on app将推送发送给拥有该应用的其他用户。我希望用户能够从列表中删除已添加的朋友。我设法修改了一些代码,但它删除了列表中的第一项。如何修改它以仅删除所选用户?
@Override
public void onPositive(MaterialDialog dialog) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("Friend");
query.whereEqualTo("user", mCurrentUser);
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> list, ParseException e) {
if (list.size() != 0)
Log.v("TAG", "sizzzze" + list.size()); //Showing 1
list.get(0).deleteInBackground(new DeleteCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Toast.makeText(getBaseContext(), "Deleted Successfully!", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getBaseContext(), "Cant Delete Tickle!" + e.toString(), Toast.LENGTH_LONG).show();
}
}
});
}
});
}
更新: @haint
// Listener for ListView item clicks
private class FriendLongClickListener implements AdapterView.OnItemLongClickListener {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
final String friend = mUserFriends.get(position).getString("user");
new MaterialDialog.Builder(MainActivity.this)
.title("Remove"+" "+mUserFriends.get(position).getUsername().toUpperCase() + "?")
.content("Do you really want to remove" + " " + mUserFriends.get(position).getUsername().toUpperCase() + " " + "from your friend list?")
.positiveText(R.string.dialog_yes)
.negativeText(R.string.dialog_no)
.callback(new MaterialDialog.ButtonCallback() {
@Override
public void onPositive(MaterialDialog dialog) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("Friend");
query.whereEqualTo("user", mCurrentUser);
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> list, ParseException e) {
if (list.size() != 0)
Log.v("TAG", "sizzzze" + list.size()); //Showing 1
list.get(0).deleteInBackground(new DeleteCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Toast.makeText(getBaseContext(), "Deleted Successfully!", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getBaseContext(), "Cant Delete Tickle!" + e.toString(), Toast.LENGTH_LONG).show();
}
}
});
}
});
}
@Override
public void onNegative(MaterialDialog dialog) {
}
})
.show();
return true;
}
}