My app crashes and deletes some other child on removing data

I am making an android app based on firebase Realtime database. I am reading the data in a recycler view. There are three items in my recycler view.

  1. Text view = Name
  2. Text view = Number
  3. Button = Delete

When I delete some child from my recycler view three things happen:

  1. Sometimes it deletes the targeted child normally

2.Sometimes it deletes some other child ( often which is below the targeted child.)

3.Sometimes my app crashes.

This is the code for my adapter:

public class holder extends RecyclerView.ViewHolder {
    public Button btnDelete;
    public TextView tvName;
    public TextView tvRoll;

    public holder(@NonNull View itemView) {
        btnDelete=(Button) itemView.findViewById(;
        tvName=(TextView) itemView.findViewById(;
        tvRoll=(TextView) itemView.findViewById(;


This is the code to show items in recycler view and code for delete button:

 options = new FirebaseRecyclerOptions.Builder<basic>()
                .setQuery(myRef, basic.class)
        adapter = new FirebaseRecyclerAdapter<basic, holder>(options) {
            protected void onBindViewHolder(@NonNull holder holder, final int i, @NonNull final basic basic) {
                holder.btnDelete.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {

            public holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.items, parent, false);
                return new holder(v);

I cannot guess where is the problem. Will anybody kindly investigate my codes? And Please also provide a practical solution.

Read more here:

Content Attribution

This content was originally published by user14253444 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: