Created
February 5, 2019 05:42
-
-
Save yfujiki/fe0651cbf4437f87cb4e05b0347c45c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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