5

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);
Andrew Stromme
  • 2,120
  • 23
  • 30
  • Hmm, maybe not possible: https://github.com/firebase/FirebaseUI-Android/issues/17 – Andrew Stromme Dec 14 '16 at 02:31
  • One way I thought of hacking this was to maintain a separate part of the firebase database that lists the active views into the data, and then update that list from the messages list. But it sounds ugly, and unnecessarily wastes network traffic. – Andrew Stromme Jan 04 '17 at 18:23
  • also see http://stackoverflow.com/questions/32396840/dynamically-change-the-limit-of-a-firebase-query-reference-on-android – Andrew Stromme Apr 05 '17 at 22:13

0 Answers0