I'm having trouble with having items in my database populate the Recycler View through FirebaseREcyclerAdapter.
In the activity controller class:
private RecyclerView hw_list;
and the connection to Firebase in onCreate() method:
hw_ref = FirebaseDatabase.getInstance().getReference().child("hardwares");
I make the adapter in the onStart() method:
@Override
protected void onStart() {
super.onStart();
FirebaseRecyclerOptions<Hardware> options =
new FirebaseRecyclerOptions.Builder<Hardware>().setQuery(hw_ref, Hardware.class).build();
FirebaseRecyclerAdapter<Hardware, AddHardwareViewHolder> adapter = new FirebaseRecyclerAdapter<Hardware, AddHardwareViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull AddHardwareViewHolder holder, int position, @NonNull Hardware model) {
holder.tv_hwTimeStamp.setText("Registered on" + model.getTimestamp());
}
@NonNull
@Override
public AddHardwareViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.hardware_row, viewGroup, false);
AddHardwareViewHolder addHardwareViewHolder = new AddHardwareViewHolder(view);
return addHardwareViewHolder;
}
};
hw_list.setAdapter(adapter);
adapter.startListening();
}
Still in the Activity, I defined the view holder:
public static class AddHardwareViewHolder extends RecyclerView.ViewHolder {
TextView tv_hwTimeStamp;
View mView;
public AddHardwareViewHolder(@NonNull View itemView) {
super(itemView);
mView = itemView;
tv_hwTimeStamp = mView.findViewById(R.id.tv_register_time);
}
}
Here's what the database looks like
And the model class 'Hardware':
public class Hardware {
public String Timestamp;
public String pid;
public Hardware() {}
public Hardware(String Timestamp, String pid) {
this.Timestamp = Timestamp;
this.pid = pid;
}
public String getTimestamp() {
return Timestamp;
}
public void setTimestamp(String Timestamp) {
this.Timestamp = Timestamp;
}
public String getPid() {
return pid;
}
public void setPid(String pid) {
this.pid = pid;
}
}
The code is free of error and warning but nothing is showing. I added breakpoint at the OnStart method where I make the adapter and adapter options. They work fine and the code run to where the adaptor starts listening.
But after that point, these override methods never get to run. It looks like it's not getting data from Firebase at all. But other parts of my App that require Firebase data all work.
FirebaseRecyclerAdapter<Hardware, AddHardwareViewHolder> adapter = new FirebaseRecyclerAdapter<Hardware, AddHardwareViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull AddHardwareViewHolder holder, int position, @NonNull Hardware model) {
holder.tv_hwTimeStamp.setText("Registered on" + model.getTimestamp());
}
@NonNull
@Override
public AddHardwareViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.hardware_row, viewGroup, false);
AddHardwareViewHolder addHardwareViewHolder = new AddHardwareViewHolder(view);
return addHardwareViewHolder;
}
};
So no item is put in the Recycler View and logcat give me this:
2018-12-05 11:47:50.282 17420-17420/com.apocalyvec.uitest3 E/RecyclerView: No layout manager attached; skipping layout
I'm really lost about what to do at this point. Maybe there are some config or initialization that I have done wrong.