回收器视图或Firebase收集查询的问题
我被困在将数据获取到回收器视图上,我不知道问题到底在哪里 如果它来自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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论