在首次启动时使用FirebaseRecyclerAdapter加

在首次启动时使用FirebaseRecyclerAdapter加

本文介绍了RecyclerView不会在首次启动时使用FirebaseRecyclerAdapter加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用

从代码中移除

为了解雇 ProgressBar ,可以将 GONE 。

  mProgressBar.setVisibility(View.GONE); 

有关更多信息,请参阅。我认为这里也报道了同样的问题。

I'm using FirebaseRecyclerAdapter to populate a RecyclerView in a Fragment.

Here's my code

mDatabase = FirebaseDatabase.getInstance().getReference();
myAdapter = new FirebaseRecyclerAdapter<Product, ProductViewHolder>(Product.class,
        R.layout.product_item,ProductViewHolder.class,
        mDatabase.child("clothes")) {
    @Override
    protected void populateViewHolder(ProductViewHolder viewHolder, Product model, int position) {
        mProgressBar.setVisibility(ProgressBar.INVISIBLE);
        viewHolder.name.setText(model.name);
        viewHolder.price.setText(model.price);
        Glide.with(getActivity()).load(model.imageUri).into(viewHolder.thumbnail);
        Log.d("NAME", model.name);
    }
};
recyclerView.setAdapter(myAdapter);

The problem is, the ProgressBar keeps moving in the first launch, it never hides and the RecyclerView never shows itself but If I exit the app and launch again, the RecyclerView is properly populated, even if the screenlocks itself and I unlock it, the RecyclerView is populated.I'm confused.

解决方案

Remove the recyclerView.setHasFixedSize(true) from your code and then check if the code works fine now.

And for dismissing the ProgressBar, its good to set the visibility to GONE.

mProgressBar.setVisibility(View.GONE);

For more information you can see this Github link. I think the same issue is reported here.

这篇关于RecyclerView不会在首次启动时使用FirebaseRecyclerAdapter加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 18:01