简体   繁体   English

如何在Firebase数据库Android中获取特定值的子代数?

[英]How to get the number of children for a specific value in firebase database android?

I am creating an app for android. 我正在为Android创建一个应用程序。 I would like to get the number of children for a specific value in the firebase database. 我想在Firebase数据库中获取特定值的子级数。 Then after the user clicks on a button, it will take that data convert it to a percentage, and display it in a textview. 然后,在用户单击按钮后,它将把该数据转换为一个百分比,并在文本视图中显示。 I can get the amount of children for each value and printing it to the monitor but when I use the same code and put it in a textview it prints out the last line, not all of it. 我可以获取每个值的子项数量并将其打印到监视器,但是当我使用相同的代码并将其放在textview中时,它会打印出最后一行,而不是全部。 So my question is how can I get the number of children for a specific value and have it be "compatible" with a textview. 所以我的问题是如何获取特定值的子级数量,并使它与textview“兼容”。

datasnapshot.getChildrenCount()方法返回将在添加到数据库引用的观察器中获得的计数。

Are you referring to getChildrenCount() ? 您是指getChildrenCount()吗? It returns the number of immediate children in your reference. 它返回您参考中的直系子代数。 The return type is long so it will be easily manipulate the value, or display it on your textView. 返回类型很长,因此可以轻松操纵该值,或将其显示在textView上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM