DEV Community

leongdiyong
leongdiyong

Posted on

dataSnapshot could not get parent push key value

I want dataSnapshot to check if "month" exist in its parents "summary". But dataSnapshot is returning that it does not have "month" in "summary"

My Firebase Database: I want to check the value (blue line) from its parent(red line)

code:
ds = FirebaseDatabase.getInstance().getReference("summary");
ds.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//summary
String key = ds.getKey();
if (dataSnapshot.hasChild("month")) {

                                Toast.makeText(newTransaction.this, "got value", Toast.LENGTH_LONG).show();
                            } else {
                                Toast.makeText(newTransaction.this, "No value", Toast.LENGTH_LONG).show();
                            }
                        }

Top comments (0)