Firebase Android如何使用键列表查询对象
我有一个与FB数据库中的对象对应的对象键列表。我想以一种高效的方式检索所有这些对象,但我不知道如何查询它们 现在我正在使用这个代码。它只是一个递归方法,可以逐个检索对象,直到找到所有对象为止。它可能非常慢Firebase Android如何使用键列表查询对象,android,firebase,firebase-queue,Android,Firebase,Firebase Queue,我有一个与FB数据库中的对象对应的对象键列表。我想以一种高效的方式检索所有这些对象,但我不知道如何查询它们 现在我正在使用这个代码。它只是一个递归方法,可以逐个检索对象,直到找到所有对象为止。它可能非常慢 private void getNextPoll(){ pollRef = rootRef.child(getString(R.string.poll_ref)).child(myPollIds.get(polls.size())); pollRef.addLi
private void getNextPoll(){
pollRef = rootRef.child(getString(R.string.poll_ref)).child(myPollIds.get(polls.size()));
pollRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Poll poll = dataSnapshot.getValue(Poll.class);
polls.add(poll);
System.out.println(poll);
//if this is the last poll, then sort the polls by date and display them
if(polls.size() == myPollIds.size()){
//Done
//sort
//display
recyclerView.setAdapter(new MyPollsListAdapter(getContext(), polls));
}else{
getNextPoll();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.e(TAG, databaseError.getMessage());
}
});
}
我的数据库是这样组织的:
我该怎么做呢
提前感谢:)您能发布数据库结构的示例吗?我已经添加了一张我的数据库的图片。为什么不创建所有eventListener,然后将其全部附加?您可以在不进行轮询的情况下设置适配器,然后在将新轮询数据添加到列表后,只需为每个侦听器调用
adapter.notifyDataSetChanged()
。或者,在向用户显示轮询对象之前,是否确实要确保检索到所有轮询对象?