回收器视图或Firebase收集查询的问题

发布于 2025-01-17 19:27:43 字数 1874 浏览 1 评论 0原文

我被困在将数据获取到回收器视图上,我不知道问题到底在哪里 如果它来自firebase查询或设置回收器视图的适配器,则回收库会创建燃烧箱中存在的项目的确切数字,但是,没有任何信息显示这是我尝试的

firebase

fun GetProductsList (fragment : Fragment) {
        var productList: ArrayList<Products> = ArrayList()
        mFireStore.collection("products")
            .get()
            .addOnSuccessListener { docSnapshot ->

                for (document in docSnapshot.documents) {
                    val productToAddToList : Products = document.toObject(Products::class.java)!!
                    productList.add(productToAddToList!!)
                }
                when (fragment) {
                    is AdminProductFragment -> {
                        fragment.SuccesProductListFromFireStore(productList)
                    }
                }

适配器

toverride fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
            val Model = productsList[position]
        if (holder is MyViewHolder ) {
            GlideLoader(context).loadProductPicture(Model.Image, holder.itemView.iv_item_image)
            holder.itemView.tv_item_name.text = Model.Name.toString()
            holder.itemView.tv_item_price.text = "${Model.Price.toString()} DZA"
        }
    }

,这是我尝试的。

if (productList.size > 0 ) {
            recyclerViewProduct.visibility = View.VISIBLE
            text_no_productFounds.visibility = View.GONE
            recyclerViewProduct.layoutManager = LinearLayoutManager(activity)
            recyclerViewProduct.setHasFixedSize(true)
            val adapterProduct = MyProductsListAdapter(requireActivity(), productList)
            recyclerViewProduct.adapter = adapterProduct
        }else{
            recyclerViewProduct.visibility = View.GONE
            text_no_productFounds.visibility = View.VISIBLE
        }

I'm getting stuck on fetching data to the recycler View I don't Know Where is the problem exactly
if it is from the Firebase Query or from setting up the adapter for the recycler view, the recyclerview creates the exact number of the items that exist in the Firebase but, No information to be shown this is what I tried

FireBase

fun GetProductsList (fragment : Fragment) {
        var productList: ArrayList<Products> = ArrayList()
        mFireStore.collection("products")
            .get()
            .addOnSuccessListener { docSnapshot ->

                for (document in docSnapshot.documents) {
                    val productToAddToList : Products = document.toObject(Products::class.java)!!
                    productList.add(productToAddToList!!)
                }
                when (fragment) {
                    is AdminProductFragment -> {
                        fragment.SuccesProductListFromFireStore(productList)
                    }
                }

Adapter

toverride fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
            val Model = productsList[position]
        if (holder is MyViewHolder ) {
            GlideLoader(context).loadProductPicture(Model.Image, holder.itemView.iv_item_image)
            holder.itemView.tv_item_name.text = Model.Name.toString()
            holder.itemView.tv_item_price.text = "${Model.Price.toString()} DZA"
        }
    }

And This

if (productList.size > 0 ) {
            recyclerViewProduct.visibility = View.VISIBLE
            text_no_productFounds.visibility = View.GONE
            recyclerViewProduct.layoutManager = LinearLayoutManager(activity)
            recyclerViewProduct.setHasFixedSize(true)
            val adapterProduct = MyProductsListAdapter(requireActivity(), productList)
            recyclerViewProduct.adapter = adapterProduct
        }else{
            recyclerViewProduct.visibility = View.GONE
            text_no_productFounds.visibility = View.VISIBLE
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文