0

所以,我正在尝试从 firebase 获取数据。为此,我将 addValueEventListener 设置为 ref 并覆盖 onDataChange 函数。在指导方针中,据说这是第一次调用,但只有在更改数据时才调用它(就像名字所暗示的那样)所以当我加载我的活动时,我在 recyclerView 中什么也得不到。在侦听器中,我将所有对象添加到 List

This is the listener:
    protected void setListener() {
        originalValueEventListener = new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                complaints.clear();
                for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                    Complaint post = postSnapshot.getValue(Complaint.class);
                    complaints.add(post);
                }
            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {

            }
        };
    }

从我的活动中,我正在使用一个函数检索这个列表:

    public   List<Complaint> getComplaints() {
        return complaints;
    }

这是我的活动:

ComplaintFeedAdapter 适配器 = 新的 ComplaintFeedAdapter(getComplaints()); recyclerView.setAdapter(适配器);

4

0 回答 0