Reputation: 111
![enter image description here][1]
mAdapter = new FirebaseRecyclerAdapter<Adapter_Hotels, Adapter_HotelsHolder>(mOptions) {
@Override
protected void onBindViewHolder(@NonNull final Adapter_HotelsHolder holder, int position, @NonNull Adapter_Hotels model) {
String key = getRef(position).getKey();
mRef1 = mRef.child(key).child("rooms");
mRef1.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
roomkey = child.getKey();
}
minmax.clear();
mRef2 = mRef1.child(roomkey).child("promos").child("regular").child(ym).child("price").child(guest);
mRef2.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()) {
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
Here is all of my queries. Is this advisable? It's totally working I removed all the codes for retrieving. My question is any other way to do this nicer or cleaner?
Upvotes: 1
Views: 194
Reputation: 599946
Your code looks a bit more complex than needed. As far as I can see you can accomplish the exact same with:
mRef1 = mRef.child(key).child("rooms");
mRef1.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot roomSnapshot: dataSnapshot.getChildren()) {
roomkey = child.getKey();
DataSnapshot priceSnapshot = roomSnapshot.child(roomkey).child("promos").child("regular").child(ym).child("price").child(guest);
System.out.println(priceSnapshot.getValue());
});
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
throw databaseError.toException();
}
});
Changes:
onCancelled
empty, as undetected errors are really hard to troubleshoot.dataSnapshot
for rooms
.Upvotes: 1
Reputation: 1385
Try this:
for (DataSnapshot child : snapshot.getChildren()) {
Log.i("TAG", "child key = " + child.getKey());
}
Upvotes: 1