Reputation: 37
The "this" in the two lines of this DailyMealFragment is having error. How could I change the "this" so that it could run in this DailyMealFragment
private fun loadRecyclerViewItems() {
val linearLayoutManager = LinearLayoutManager(this)
binding.itemsRv.layoutManager = linearLayoutManager
val itemList:ArrayList<RestaurantsModels> = ArrayList()
for (i in titles.indices){
val model = RestaurantsModels(titles[i], descriptions[i], images[i])
itemList.add(model)
}
val adapterItem = RestaurantsAdapter(this, itemList)
binding.itemsRv.adapter = adapterItem
}
Upvotes: 0
Views: 70
Reputation: 109
LinearLayoutManager(requireContext())
do something like this. and for adapter
create val adapterItem by lazy { RestaurantsAdapter() }
on the top of your adapter class after imports
private fun loadRecyclerViewItems() {
val linearLayoutManager = LinearLayoutManager(requireContext())
binding.itemsRv.layoutManager = linearLayoutManager
val itemList:ArrayList<RestaurantsModels> = ArrayList()
for (i in titles.indices){
val model = RestaurantsModels(titles[i], descriptions[i], images[i])
itemList.add(model)
}
binding.itemsRv.adapter = adapterItem
}
Upvotes: 2