Created
October 25, 2020 10:01
-
-
Save seanghay/f419deb2202560f298fad90fae999cc9 to your computer and use it in GitHub Desktop.
ViewBinding inside Fragment
This file contains 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 HomeFragment : Fragment() { | |
private var _binding: FragmentHomeBinding? = null | |
private val binding: FragmentHomeBinding get() = _binding!! | |
override fun onCreateView( | |
inflater: LayoutInflater, | |
container: ViewGroup?, | |
savedInstanceState: Bundle? | |
): View? { | |
_binding = FragmentHomeBinding.inflate(inflater, container, false) | |
return binding.root | |
} | |
override fun onDestroyView() { | |
super.onDestroyView() | |
// calling this to avoid memory leak. | |
_binding = null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment