Loading more items on user scroll with FirebaseIndexRecyclerAdapter

1.6k views Asked by At

I'm using a FirebaseIndexRecyclerAdapter as described on https://github.com/firebase/FirebaseUI-Android/tree/master/database. But my list has many items and I want to only load a few items at first and then lazy load the rest when the user scrolls up.

My first thought was that I could use mKeyRef.limitToLast(5) but then updating this requires recreating the Adapter, right?

How do I achieve this lazy-loading mechanic?

RecyclerView recycler = (RecyclerView) findViewById(R.id.messages_recycler);
recycler.setHasFixedSize(true);
recycler.setLayoutManager(new LinearLayoutManager(this));

mAdapter = new FirebaseIndexRecyclerAdapter<Chat, ChatHolder>(
  Chat.class,
  android.R.layout.two_line_list_item,
  ChatHolder.class, mIndexRef,
  mDataRef) {
    @Override
    public void populateViewHolder(ChatHolder chatMessageViewHolder, Chat chatMessage, int position) {
        chatMessageViewHolder.setName(chatMessage.getName());
        chatMessageViewHolder.setText(chatMessage.getText());
    }
};
recycler.setAdapter(mAdapter);
0

There are 0 answers