I got some problems in my program, when it runs the recycleView not working and it say "No adapter attached; skipping layout", i have no clue to fix the error
heres the code
Main Activity
override fun onProductsLoadSuccess(productsModelList: List<Products>?) {
val adapter = ProductsAdapter(this, productsModelList!!)
rv_produk.adapter = adapter
rv_produk.addItemDecoration(SpaceItemDecoration())
}
private fun init() {
productsLoadListener = this
val gridLayoutManager = GridLayoutManager(this,1)
rv_produk.layoutManager = gridLayoutManager
}
ProductAdapter
class ProductsAdapter(
private val context: Context,
private val list: List<Products>
): RecyclerView.Adapter<ProductsAdapter.ProductsViewHolder>() {
class ProductsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
var gambarProduk: ImageView? = null
var namaProduk: TextView? = null
var hargaProduk: TextView? = null
init {
gambarProduk = itemView.findViewById(R.id.gambar_produk) as ImageView
namaProduk = itemView.findViewById(R.id.nama_produk) as TextView
hargaProduk = itemView.findViewById(R.id.harga_produk) as TextView
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProductsViewHolder {
return ProductsViewHolder(LayoutInflater.from(context)
.inflate(R.layout.item_product,parent,false))
}
override fun onBindViewHolder(holder: ProductsViewHolder, position: Int) {
Glide.with(context)
.load(list[position].image)
.into(holder.gambarProduk!!)
holder.namaProduk!!.text = StringBuilder().append(list[position].name)
holder.hargaProduk!!.text = StringBuilder("Rp").append(list[position].price)
}
override fun getItemCount(): Int {
return list.size
}
}
Please Help me
I wanna build a recycler view with realtime database on firebase