This question already has answers here:
How to retrieve only new data?
                                
                                    (2个答案)
                                
                        
                                3年前关闭。
            
                    
我尝试先获取所有数据,然后再返回值...但是我在网上找不到关于firebaseoperation的完成处理程序的信息。

有人可以帮忙吗?

我当前的实现效果不佳...

public List<ExampleClass> GetAllExamples() {
  Query examplequery = db.child("example");
  exampleList = new ArrayList<ExampleClass>();

  examplequery.addChildEventListener(new ChildEventListener() {

    @Override
    public void onChildAdded(DataSnapshot dataSnapshot, String s) {
      String value = getValue(dataSnapshot.getValue().toString());
      String key = dataSnapshot.getKey();
      ExampleClass ex = new Country(key, value);
      exampleList.add(ex);
    }

    @Override
    public void onChildChanged(DataSnapshot dataSnapshot, String s) {

    }

    @Override
    public void onChildRemoved(DataSnapshot dataSnapshot) {

    }

    @Override
    public void onChildMoved(DataSnapshot dataSnapshot, String s) {

    }

    @Override
    public void onCancelled(FirebaseError firebaseError) {

    }
  });

  return exampleList;
}

最佳答案

在弗兰克的帮助下,我找到了合适的解决方案

examplequery.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            // do something after data is synchronized
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {

        }
    });

关于java - Android中的完成处理程序Firebase ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38284964/

10-10 08:21