I'm using RecyclerView with databindings but when I run the app the first time nothing is showing up then after update some content or update the app via instant Run the content appears.
my ViewHolder:
class MyViewHolder extends RecyclerView.ViewHolder {
private ItemBinding mBinding;
public MyViewHolder(View itemView) {
super(itemView);
mBinding = DataBindingUtil.bind(itemView);
}
ItemBinding getBinding() {
return mBinding;
}
}
my Adapter:
public class MyAdapter extends FirebaseRecyclerAdapter<MyModel, MyViewHolder> {
public MyAdapter(Query ref) {
super(MyModel.class, R.layout.my_item, MyViewHolder.class, ref);
}
@Override
protected void populateViewHolder(MyViewHolder viewHolder, MyModel model, int position) {
ItemBinding binding = viewHolder.getBinding();
binding.setMyModel(model);
binding.executePendingBindings();
}
}
I found in some other question I need call binding.executePendingBindings()
that was I did without success.
Edit
I just added a log call:
Log.d(BuildConfig.TAG, "called populateViewHolder " + position);
on the populateViewHolder
method. The log is never printed.
Edit 2
The way how I'm initializing my recyclerView:
// onCreate
LinearLayoutManager llm = new LinearLayoutManager(this);
llm.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view)
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(llm);
mRef = FirebaseDatabase.getInstance().getReference().child(CHILD_TREE)
// onStart
mAdapter = new MyAdapter(mref.orderByChild("date"));
mRecyclerView.setAdapter(mAdapter);