Retrieve data to text view from fire base without parent key

  • Replies:3
  • Answered
Gagana Lakruwan
  • Forum posts: 2

May 13, 2018, 4:16:08 AM via Website

image
here i want to search details using child without use parent key. according to this database,i want to get price and category using Name.without using parent key ("kjhsfkgkrlhg"),("get price,category where Name="super Creamcracker")

Reply
Best answer
Gagana Lakruwan
  • Forum posts: 2

May 18, 2018, 3:12:44 PM via Website

i found solution,this is that code
String pris="super Creamcracker";
DatabaseReference ref=FirebaseDatabase.getInstance().getReference().child("Items");
ref.orderByChild("Name").equalTo(pris).addValueEventListener(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot datas: dataSnapshot.getChildren()){
String keys=datas.child("Price").getValue().toString();
pric.setText(keys);
}

}

@Override
public void onCancelled(DatabaseError databaseError) {

}

});
Helpful?
Miguel Courts
Reply
Bob Stone
  • Forum posts: 12

May 18, 2018, 2:56:42 PM via Website

I don't think so it is possible. Will let you know if find any solution.

Helpful?
Reply
Best answer
Gagana Lakruwan
  • Forum posts: 2

May 18, 2018, 3:12:44 PM via Website

i found solution,this is that code
String pris="super Creamcracker";
DatabaseReference ref=FirebaseDatabase.getInstance().getReference().child("Items");
ref.orderByChild("Name").equalTo(pris).addValueEventListener(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot datas: dataSnapshot.getChildren()){
String keys=datas.child("Price").getValue().toString();
pric.setText(keys);
}

}

@Override
public void onCancelled(DatabaseError databaseError) {

}

});
Helpful?
Miguel Courts
Reply
Miguel Courts
  • Forum posts: 1

Dec 2, 2018, 10:18:40 PM via Website

I just wanted to say thanks for this, helped me solve something i was missing :D much appreciated!

Helpful?
Reply