My favourites fragment does not display the data given correctly unless the onCreateView function is called. This means that the fragment needs to be deleted and created again. Is there a way to appropriately refresh the fragment in the onResume method?
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val fragment = this
_binding = FragmentFavouritesBinding.inflate(layoutInflater)
binding.recyclerView.apply{
layoutManager = GridLayoutManager(activity,2)
adapter= CardAdapter(favouriteList, fragment)
}
return binding.root
}
override fun onResume() {
super.onResume()
orderFavourites()
sortFavourites()
if(favouriteList.isEmpty()){
Toast.makeText(this.context,"No Favourites Found", Toast.LENGTH_SHORT).show()
}
else{
Toast.makeText(this.context,"resumed", Toast.LENGTH_SHORT).show()
}
}
The favouriteList is updated in another activity and I have ensured that it contains the correct values. It displays as intended after deleting and creating the fragment once more.