I am using Realtime database and I want to get the position of the selected recycler view item and delete it, the only problem is in this part " String id = list.get(position).getId();" I can't seem to get the position of my selected item.
The error: "Cannot resolve symbol 'position'".
My dialog code:
private void showDialog() {
AlertDialog alertDialog = new AlertDialog.Builder(upcoming.this).create();
alertDialog.setTitle("Confirm Delete");
alertDialog.setMessage("Are you sure ypu want to delete this item?");
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Delete", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String id = list.get(position).getId();
Query queryRef = database.child("Reminder").orderByChild("id").equalTo(id);
queryRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot snapshot, String previousChild) {
snapshot.getRef().setValue(null);
}