Skip to content

Instantly share code, notes, and snippets.

@yfujiki
Created February 5, 2019 05:42
Show Gist options
  • Select an option

  • Save yfujiki/fe0651cbf4437f87cb4e05b0347c45c8 to your computer and use it in GitHub Desktop.

Select an option

Save yfujiki/fe0651cbf4437f87cb4e05b0347c45c8 to your computer and use it in GitHub Desktop.
class MainActivityFragment : Fragment() {
// Discard permanent reference to the adapter
val adapter = MainRecyclerViewAdapter()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
return inflater.inflate(R.layout.fragment_activity_main, container, false)
}
+ override fun onDestroyView() {
+ super.onDestroyView()
+ // Note that this recyclerView is an old one
+ // and different instance from the one in onViewCreated.
+ recyclerView.adapter = null
+ }
+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// Note that this recyclerView is a new one
// and different instance from the one in onDestroyView.
recyclerView.adapter = adapter
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment