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();
}
};
}