Loading data with FirebaseUI from Realtime Database

155 views
Skip to first unread message

Norman Laudien

unread,
Jun 14, 2018, 7:01:34 PM6/14/18
to Firebase Google Group
Hello,

i try to figure out how to exactly load data from Realtime Database into my RecyclerView using FirebaseRecyclerAdapter.

I have found out that in onChildChanged() the correct snapshots are loaded, but onCreateViewHolder() and onBindViewHolder() never get called.

Thanks in advance.

@NonNull
@Override
protected RecyclerView.Adapter onCreateRecyclerViewAdapter() {
Query query = FirebaseDatabase.getInstance().getReference("lexiconCandidates")
.orderByChild("readyToApprove")
.equalTo(true);
FirebaseRecyclerOptions<Lexicon> options = new FirebaseRecyclerOptions.Builder<Lexicon>()
.setLifecycleOwner(this)
.setQuery(query, Lexicon.class)
.build();
return new FirebaseRecyclerAdapter<Lexicon, LexiconViewHolder>(options) {
@NonNull
@Override
public LexiconViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
ListItemLexiconBinding binding = DataBindingUtil.inflate(layoutInflater, R.layout.list_item_lexicon, parent, false);
return new LexiconViewHolder(binding);
}

@Override
protected void onBindViewHolder(@NonNull LexiconViewHolder holder, int position, @NonNull Lexicon lexicon) {
holder.bind(lexicon);
}

@Override
public void onError(@NonNull DatabaseError error) {
super.onError(error);
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show();
}


};
}

Samuel Stern

unread,
Jun 15, 2018, 12:13:38 PM6/15/18
to fireba...@googlegroups.com
Hi Norman,

Have you called startListening() on the adapter?  Have you added a LayoutManager to the RecyclerView?  Those are two common reasons for the issue you are seeing.

- Sam

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/e856af27-6ffc-4eb0-a7e1-0c301c6d8cdd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Norman Laudien

unread,
Jun 15, 2018, 1:37:12 PM6/15/18
to Firebase Google Group
Thanks for your answer. I forgot to set a layout manager that was it... thank you.
Reply all
Reply to author
Forward
0 new messages