Reputation: 642
I am migrating my app from Java to Kotlin. I have generated app with default Navigation drawer and renamed the Fragments associated with navigation drawer items.
These Fragments (Home, Settings, Notification) contains some UI elements and one of them, HomeFragment contains a viewpager with five(5) views in it. I have implemented everything correctly and everything following this tutorial which works fine until I resume the app.
As soon as I press the home button and resume the app, I get blank screen but I can see actionbar/ toolbar properly.
Pager adapter
class PagerAdapter(manager: FragmentManager):FragmentStatePagerAdapter(manager,BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT){
override fun getCount(): Int {
return 5;
}
override fun getItem(position: Int): Fragment {
return when (position) {
0 -> OneFragment.newInstance()
1 -> TwoFragment.newInstance()
2 -> ThreeFragment.newInstance()
3 -> FourFragment.newInstance()
4 -> FiveFragment.newInstance()
else -> OneFragment.newInstance()
}
}
override fun setPrimaryItem(container: ViewGroup, position: Int, `object`: Any) {
super.setPrimaryItem(container, position, `object`)
}
}
This is where I am attaching this viewpager in the HomeFragment. I have created the viewbind class following this tutorial.
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val pagerAdapter = PagerAdapter(childFragmentManager)
binding?.homePager?.adapter = pagerAdapter
}
I also get a lot of warnings -
This app literally with just default code generated by android. except one recyclerview. No heavy UI operation going on becuase I am just passing a predefined string array in recyclerviewadapter.
Upvotes: 0
Views: 136