If a user clicks/taps on an item, you'll get the position of that item from Android.
With that you can call adapter.getRef(position).remove().
Puf, how can you delete the item from the viewholder?
@puf, I'm also wondering how you delete the item from the viewholder? Seems like the viewholder doesn't know about the adapter.
@astromme Simply create a DatabaseReference setter in your viewholder:
public void setRef(DatabaseReference ref) {
mRef = ref;
}
// Do other stuff like setting a click listener
Yes Me to I have the same probleme i want to delete only from the View (recyclerview ) and not for the database ! any solutions ! ?
i have an item using a relative layout for view holder in recycleview, it have an id to declare it in code. so when populating view to bind the data on viewholder i just need to call removeAllViewsInLayout() to make it dissapear from recycleview and not delete the real data on firebase.
this is who can solve my problem i tired to much
mRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
CourseModel courseModel=dataSnapshot.getValue(CourseModel.class);
courseModelslist.add(courseModel);
arrayKeyList.add(dataSnapshot.getKey());
courseAdapter=new CourseAdapter(RetriveCourse.this,courseModelslist);
recyclerView.setAdapter(courseAdapter);
courseAdapter.notifyDataSetChanged();
// for (DataSnapshot ds:dataSnapshot.getChildren())
// {
// CourseModel courseModel=ds.getValue(CourseModel.class);
// courseModelslist.add(courseModel);
//
// }
// courseAdapter=new CourseAdapter(RetriveCourse.this,courseModelslist);
// recyclerView.setAdapter(courseAdapter);
// courseAdapter.notifyDataSetChanged();
}
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {
// String key=dataSnapshot.getKey();
}
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
how to delete data from recyclerview and also from firebase database.....i used customer adapter extends from recyclerview adapter ....plz help me anyone
?
Most helpful comment
@astromme Simply create a
DatabaseReferencesetter in your viewholder: