Firebaseui-android: how to delete item

Created on 20 Feb 2016  路  9Comments  路  Source: firebase/FirebaseUI-Android

Most helpful comment

@astromme Simply create a DatabaseReference setter in your viewholder:

public void setRef(DatabaseReference ref) {
    mRef = ref;
}

// Do other stuff like setting a click listener

All 9 comments

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

?

Was this page helpful?
0 / 5 - 0 ratings