Search code examples
androidfirebaseandroid-recyclerviewfirebase-realtime-databasefirebaseui

FirebaseRecyclerAdapter - How to grab the last item?


I need to grab the last List Item (CardView) coming from a FirebaseRecyclerAdapter in order do add extra bottom padding to it.

The problem is that the FirebaseRecyclerAdapter works a bit differently than a RecyclerView and doesn't have an Array or List of items passed to it, but a Firebase Database Reference.

So I can't do this. For example:

@Override
public void onBindViewHolder(UserViewHolder userViewHolder, int position) {

   if( position == getItemCount() - 1 ){
      // Your last item
   }

}

Could anyone help please?


Solution

  • Here is my try that might help you:

    FirebaseRecyclerAdapter.getItemCount() as its docementation is copied from RecyclerView.Adapter (still no big difference):

    Returns the total number of items in the data set held by the adapter.

    Instead of onBindViewHolder() you can do that in populateViewHolder():

    @Override
    protected void populateViewHolder(VH viewHolder, T model, int position)
    {
        if (position == getItemCount() - 1)
        {
    
        }
    }