I have this node called " Orders " in my Firebase database, this node stores as children nodes, the unique ID of each " Order em> ", the ID, in turn, has the same ID, the rout of the user who requested the order, the status, and a node" orderItems ", which stores the products requested in the order.
My idea is to capture the data of each order and recycle them with RecyclerView in a Cardview . However, I manage to capture the individual data (without children), but I do not know how to capture the child node " orderItems ", do you work with ArrayList or how could it be done?
I attach the ViewHolder code
public class RecievedOrderViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView txtRutUser,txtProdName,txtProdQuantity;
public RecievedOrderViewHolder (View itemView){
super(itemView);
txtRutUser = (TextView)itemView.findViewById(R.id.txtRutCliente);
txtProdName = (TextView)itemView.findViewById(R.id.txtProductName);
txtProdQuantity = (TextView)itemView.findViewById(R.id.txtProductQuantity);
}
@Override
public void onClick(View v) {
}
}
And the Activity code where the RecyclerView is loaded
public class RecievedOrdersActivity extends AppCompatActivity {
RecyclerView recyclerViewOrders;
RecyclerView.LayoutManager layoutManagerOrders;
RecyclerView.LayoutManager layoutManagerOrdersProducts;
FirebaseDatabase db;
DatabaseReference tableOrders;
FirebaseRecyclerAdapter<Order, RecievedOrderViewHolder> adapterOrders;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recieved_orders);
db = FirebaseDatabase.getInstance();
tableOrders = db.getReference("Orders");
recyclerViewOrders = (RecyclerView)findViewById(R.id.listOrders);
recyclerViewOrders.setHasFixedSize(true);
layoutManagerOrders = new LinearLayoutManager(this);
recyclerViewOrders.setLayoutManager(layoutManagerOrders);
layoutManagerOrdersProducts = new LinearLayoutManager(this);
loadListOrder();
}
private void loadListOrder() {
adapterOrders = new FirebaseRecyclerAdapter<Order, RecievedOrderViewHolder>(Order.class,R.layout.order_item,RecievedOrderViewHolder.class,tableOrders) {
@Override
protected void populateViewHolder(RecievedOrderViewHolder viewHolder, Order model, int position) {
viewHolder.txtRutUser.setText(model.getRutUser());
}
};
recyclerViewOrders.setAdapter(adapterOrders);
}
}
So far, I only set the user's routine, but I do not know how to access the values of the orderItems node, and capture that data and then set them. Because I understand that in the adapter as a parameter, the POJO class is placed and then used to call " model.getAtributo () ". The drama is that " orderItems ", contains objects of the POJO Product class, this is my doubt.