此Firebase查询(orderbyKey)无法显示任何内容

时间:2016-06-12 15:38:53

标签: android firebase firebase-realtime-database

我正在尝试从子进程中获取数据(" REPORTS"),其中datasnapshot.getRef与从getIntent传递的密钥相同,没有显示,我无法分辨代码语法有什么问题

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(),
      newPost.get("DESCRIPTION").toString().trim(),
      newPost.get("MEAL_INGREDIENTS").toString().trim(),

1 个答案:

答案 0 :(得分:0)

看起来您正在尝试加载单个报告。在这种情况下,您需要:

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(
        dataSnapshot.child("MEAL_TITLE").getValue(String.class).trim(),
        dataSnapshot.child("DESCRIPTION").getValue(String.class).trim(),
        dataSnapshot.child("MEAL_INGREDIENTS").getValue(String.class).trim(),