I Created Horizontal Cards But They Arent Showing In My Fragments?
I tried to create horizontal RecyclerView and Bottom Navigation View. I made horizontal_card_item.xml, HorizontalView.kt (class), DataSource.kt , and HorizontalViewAdapter File, fo
Solution 1:
Check if this works. If not, post the issue you face after this change.
classMainActivity : AppCompatActivity() {
privatelateinitvar horizontalViewAdapter: HorizontalViewAdapter
overridefunonCreate(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()
}
privatefuninitRecyclerView(){
val recycler_view = findNavController(R.id.nav_host_fragment)
recycler_view.apply {
var layoutManager = LinearLayoutManager(this@MainActivity)
val topSpacingDecorator = TopSpacingItemDecoration(30)
addItemDecoration(topSpacingDecorator)
horizontalViewAdapter = HorizontalViewAdapter()
recycler_view.adapter = horizontalViewAdapter
}
}
privatefunaddDataSet(){
valdata = DataSource.createDataSet()
horizontalViewAdapter.updateData(data)
}
privatefunaddItemDecoration(topSpacingDecorator: TopSpacingItemDecoration) {}
}
HorizontalViewAdapter:
classHorizontalViewAdapter{
funupdateData(data) {
this.data = data// Notify that the data is changed
notifyDataSetChanged()
}
// Everything else
}
Post a Comment for "I Created Horizontal Cards But They Arent Showing In My Fragments?"