[英]android firebase database how to retrieve all data from child node
[英]How to retrieve all the data from a node in Android Firebase realtime database?
这是我的 firebase 数据:
我想从 child("Registo Incial e Final") 中检索所有数据并显示在表格或列表视图中。
我来自 android 工作室的代码:
reff2 = database.getInstance().getReference().child("Registo Inicial e Final");
reff2.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange( DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
Log.e("MATRICULAAAAAAAAAAAAA", String.valueOf(ds.child("matricula").getValue()));
try {
if (ds.child("matricula").getValue().equals(editText_Matric.getText().toString())) {
String message = ds.child("nome_CONDUTOR").getValue().toString();
String message2 = ds.child("matricula").getValue().toString();
String message3 = ds.child("cod_PROJETO").getValue().toString();
String message4 = ds.child("km_INICIAL").getValue().toString();
String message5 = ds.child("km_FINAL").getValue().toString();
String message6 = ds.child("data_INICIO").getValue().toString();
String message7 = ds.child("data_FIM").getValue().toString();
String message8 = ds.child("hora_INICIO").getValue().toString();
String message9 = ds.child("hora_FIM").getValue().toString();
String message10 = ds.child("observacoes").getValue().toString();
Nome.setText(message);
Matricula.setText(message2);
Cod.setText(message3);
Kilometros_inicial.setText(message4);
Kilometros_final.setText(message5);
Data_inicial.setText(message6);
Data_final.setText(message7);
Hora_inicial.setText(message8);
Hora_final.setText(message9);
Observacoes.setText(message10);
Output:
它仅显示来自一条记录的数据(仅来自一个 firebase 按键),但我想要来自所有按键的所有数据..
您没有读取所有数据,因为您指定了一个if-statement
来仅获取在EditText
中键入的相应matricula
字符串的那些:
删除此if-statement
if (ds.child("matricula").getValue().equals(editText_Matric.getText().toString())) {
......
.....
你会得到所有的值然后可能将它们存储在一个list
发生的事情是您正在获取所有孩子的整个快照,然后您的语句if (ds.child("matricula").getValue().equals(editText_Matric.getText().toString()))
被过滤掉所有其他孩子,除了matricula
等于editText_Matric
中的 txt 的地方。 在您的屏幕截图中,它显示您的 editText_Matric 文本值为“90-29-VE”,因此您只得到了 Miguel Carvalho 的一个结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.