I have implemented a View Pager in my app. It slides between to fragments, the problem is, even if only the first fragment is being display, the other fragment gets created. That causes problems because, in the second fragment I'm displaying a Loading Bar and this way it shows in the first fragment instead of the second one.
This is my ViewPager code:
class FragmentViewPagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) {
override fun getItem(position: Int): Fragment {
if (position == 0){
return VentFragment()
}
return ConversationsFragment()
}
override fun getCount(): Int {
return 2
}
}
In the second fragment I call the Loading Bar this way in onCreateView
:
loading = ProgressDialog(context)
loading.setTitle(getString(R.string.loading))
loading.setMessage(getString(R.string.fetching_your_data))
loading.setCanceledOnTouchOutside(false)
loading.show()
Is it because of the context? I can't seem to find the bug...