Exchange

Children Count in Firebase Real-time Database Android Studio

 

private void countAndSum() {
FirebaseDatabase.getInstance().getReference().child("Hospital").child("Users").child(uid).child("Cart")
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {


if(snapshot.exists()){

int numberOfItems = (int) snapshot.getChildrenCount();
Toast.makeText(CartActivity.this, String.valueOf(numberOfItems), Toast.LENGTH_SHORT).show();

}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});
}


Post a Comment

0 Comments