I'm trying to Retrieving Data from database for my recView.
I want to get A child nodes (a,b,c), B child nodes and add it to my model.
but I can't get all. I need to use model.add(modela) or model.add(modelb) but i want all models to add my list. What should i do?
Here is my code;
List<Model> model= new ArrayList<>();
FirebaseDatabase.getInstance()
.getReference(path_road).child(AAA).child("AA")
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull @NotNull DataSnapshot snapshot) {
for (DataSnapshot AsnapShot : snapshot.getChildren()) {
Model modela = AsnapShot.child("A").getValue( class );
Model modelab= AsnapShot.child("B").getValue( class );
model.add(i want to add here childA and childB);
If the names are always A
and B
, you can make a parent model class (say ParentModel
) that looks like this:
public class ParentModel {
@PropertyName("A")
public Model modela;
@PropertyName("B")
public Model modelb;
}
The above is the minimum class that can work, but you can also add getters and setters of course.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.