如何在Firebase中找到值?

时间:2017-03-25 17:31:51

标签: android firebase firebase-realtime-database

这是我的代码:

mFirebaseDatabae = FirebaseDatabase.getInstance();
mMessageReference = FirebaseDatabase.getInstance().getReference().child("memos");

serchButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

        mMessageReference.orderByChild("title").equalTo("z").addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                Toast.makeText(SerchActivity.this, "print", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
    }
});

这是我的Firebase树:

enter image description here

只有当标题是z?

时,才能打印标题

1 个答案:

答案 0 :(得分:2)

像这样的方式......

for (DataSnapshot messageSnapshot : dataSnapshot.getChildren()) {
    String title= (String) messageSnapshot.child("title").getValue();
}