Vincent Macharia Vincent Macharia - 1 year ago 111
Android Question

This Firebase query(orderbyKey) cannot display anything

I am trying to fetch data from child("REPORTS")where datasnapshot.getRef is the same as key passed from getIntent,there is no display and I cannot tell what is wrong with code syntax

Intent i = getIntent();
final String key = i.getExtras().getString("firekey");

Query queryRef = mDatabase.child("REPORTS").equalTo(key).orderByKey();
queryRef.addChildEventListener(new ChildEventListener() {
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Log.d( "Post", "data");
Map<String, Object> newPost = (Map<String, Object>) dataSnapshot.getValue();
if (newPost != null) {
reportSingle = new FoodItem(newPost.get("MEAL_TITLE").toString().trim(),

Answer Source

It looks like you're trying to load a single report. In that case, you'll need:

DatabaseReference reportRef = mDatabase.child("REPORTS").child(key);
reportRef.addValueEventListener(new ValueEventListener() {
  public void onDataChanged(DataSnapshot dataSnapshot) {
    Log.d( "Post", "data");
    if (dataSnapshot.exists()) {
      reportSingle = new FoodItem(
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download