Here is my Firebase structure
I'm trying to select all the IDs with the same date and populate a recycler view with it, here is my code snippet:
private void updateValues()
{
if(rAuth !=null && rUser!=null)
{
final String date="15/03/2018";
final DatabaseReference rRef =
FirebaseDatabase.getInstance().getReference()
.child("Users")
.child("Transactions");
rRef.child("Expense").addValueEventListener(new ValueEventListener()
{
@Override
public void onDataChange(DataSnapshot rSnap)
{
for(DataSnapshot d: rSnap.getChildren())
{
rRef.child(d.getKey())
.child("Date")
.addListenerForSingleValueEvent(new ValueEventListener()
{
@Override
public void onDataChange(DataSnapshot dataSnapshot)
{
if(date.equals(dataSnapshot.getValue().toString()))
{
recordItems.add(new recordItems(iconGetter(d.child("Type").getValue().toString()),
d.child("Description").getValue().toString(),
d.child("Type").getValue().toString(),
d.child("Value").getValue().toString(),
d.child("Date").getValue().toString()));
}
}
@Override
public void onCancelled(DatabaseError databaseError)
{
}
});
}
initRecycler();
}
@Override
public void onCancelled(DatabaseError databaseError)
{
}
});
now since i'm trying to access DataSnapshot d from an inner class I need to make it final, but if I do that, I can't iterate it anymore. I am a bit stuck here since it's my first time using Firebase. I have only used SQL in the past.
recordItems is my model(is that what it's called?) class for storing and providing values to the recycler adapter
Is there a better way to do this? I need to sort these by date, I thought about restructuring the database but I would prefer if there was another way.
Forgive my messy code, I intend to fix it once I get it working. Thanks for any help in advance.