Solution 1 :
Check if this works. If not, post the issue you face after this change.
class MainActivity : AppCompatActivity() {
private lateinit var horizontalViewAdapter: HorizontalViewAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val navView: BottomNavigationView = findViewById(R.id.nav_view)
val navController = findNavController(R.id.nav_host_fragment)
val appBarConfiguration = AppBarConfiguration(setOf(
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications))
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
initRecyclerView()
addDataSet()
}
private fun initRecyclerView(){
val recycler_view = findNavController(R.id.nav_host_fragment)
recycler_view.apply {
var layoutManager = LinearLayoutManager([email protected])
val topSpacingDecorator = TopSpacingItemDecoration(30)
addItemDecoration(topSpacingDecorator)
horizontalViewAdapter = HorizontalViewAdapter()
recycler_view.adapter = horizontalViewAdapter
}
}
private fun addDataSet(){
val data = DataSource.createDataSet()
horizontalViewAdapter.updateData(data)
}
private fun addItemDecoration(topSpacingDecorator: TopSpacingItemDecoration) {}
}
HorizontalViewAdapter:
class HorizontalViewAdapter {
fun updateData(data) {
this.data = data
// Notify that the data is changed
notifyDataSetChanged()
}
// Everything else
}
Problem :
I tried to create horizontal RecyclerView
and Bottom Navigation View
.
I made horizontal_card_item.xml
, HorizontalView.kt
(class), DataSource.kt
, and HorizontalViewAdapter
File, for recyclerView.
Main Activity.kt:
class MainActivity : AppCompatActivity() {
private lateinit var horizontalViewAdapter: HorizontalViewAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val navView: BottomNavigationView = findViewById(R.id.nav_view)
val navController = findNavController(R.id.nav_host_fragment)
val appBarConfiguration = AppBarConfiguration(setOf(
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications))
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
initRecyclerView()
addDataSet()
}
private fun initRecyclerView(){
val recycler_view = null
recycler_view.apply {
var layoutManager = LinearLayoutManager([email protected])
val topSpacingDecorator = TopSpacingItemDecoration(30)
addItemDecoration(topSpacingDecorator)
horizontalViewAdapter = HorizontalViewAdapter()
var adapter = horizontalViewAdapter
}
}
private fun addDataSet(){
val data = DataSource.createDataSet()
// HorizontalViewAdapter.SubmitList(data)
}
private fun addItemDecoration(topSpacingDecorator: TopSpacingItemDecoration) {}
}
Error:
E/RecyclerView: No adapter attached; skipping layout
E/eglCodecCommon: GoldfishAddressSpaceHostMemoryAllocator: ioctl_ping failed for device_type=5, ret=-1
Comments
Comment posted by ZSergei
Why you set
Comment posted by Goodie123
Plus I dont think you need the “var” before the adapter, it already knows that adapter variable exists.
Comment posted by Riddhi Dua
Because ‘findViewById’ is showing an error ‘Not enough information to infer type variable T’ @ZSergei
Comment posted by Riddhi Dua
Using this [adapter = horizontalViewAdapter] shows an error in adapter of [Unresolved reference: adapter] @Goodie123
Comment posted by Goodie123
val recyclerView: RecyclerView = findViewById(R.id.recycler_view_id) and then do the apply without the val. It doesnt know what type of variable it is.
Comment posted by Riddhi Dua
unresolved reference for [adapter] and [createDataSet()]
Comment posted by chat.stackoverflow.com/rooms/215419/abhis-chat-room
@RiddhiDua Please add the new error in the question. Possibly with the error line. We can continue our conversation here :