Firebase Firestore返回空数组

时间:2018-07-31 09:25:52

标签: android google-cloud-firestore firebaseui

当我查询集合中的文档时,我的Firebase FirestoreRecyclerOptions返回一个空数组。任何帮助调试将不胜感激。

My Firestore DB Structure 我班上有地图的get和setter方法:

public class Post {
    private String username, uid, photo_url, caption;
    private int likes, shares;
    private Date timestamp;

    public Post(String username, String uid, String photo_url, String caption, int likes, int shares, Date timestamp) {
        this.username = username;
        this.uid = uid;
        this.photo_url = photo_url;
        this.caption = caption;
        this.likes = likes;
        this.shares = shares;
        this.timestamp = timestamp;
    }

    public Post() {
    }
}

这是我在使用FirestoreRecyclerAdapter之前查询数据库的地方:

CollectionReference reference = db.collection("posts");

    Query query = reference.orderBy("likes", Query.Direction.DESCENDING);

    // Configure recycler adapter options:
    //  * query is the Query object defined above.
    //  * Chat.class instructs the adapter to convert each DocumentSnapshot to a Chat object
    FirestoreRecyclerOptions<Post> options = new FirestoreRecyclerOptions.Builder<Post>()
            .setQuery(query, Post.class)
            .build();

    Log.w(TAG, options.getSnapshots().toString());

然后将回收站视图设置为我的已创建适配器:

FirestoreRecyclerAdapter adapter = new FirestoreRecyclerAdapter<Post, PostHolder.ViewHolder>(options) {
            @NonNull
            @Override
            public PostHolder.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

                View view = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.single_post_layout, parent, false);

                return new PostHolder.ViewHolder(view);
            }

            @Override
            protected void onBindViewHolder(@NonNull PostHolder.ViewHolder holder, int position, @NonNull Post model) {
                holder.tv_username.setText(model.getUsername());
            }
        };

        rv_posts.setAdapter(adapter);

0 个答案:

没有答案