YMLEE
YMLEE

Reputation: 23

How to find a value in Firebase?

Here is my code:

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) {

            }
        });
    }
});

Here is my Firebase tree:

enter image description here

Isn't it possible for the title to be printed only when the title is z?

Upvotes: 0

Views: 173

Answers (1)

Jd Prajapati
Jd Prajapati

Reputation: 1971

Fatch like this way...

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

Upvotes: 2

Related Questions