Created
May 21, 2022 17:24
-
-
Save trevorhackman/aa588e591bbaf1aed04a7114b5767a0f to your computer and use it in GitHub Desktop.
Android View Binding Without Boilerplate - Part 2 - 4
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
abstract class ViewBindingFragment<T: ViewBinding>( | |
private val inflate: (LayoutInflater, ViewGroup?, Boolean) -> T | |
): Fragment() { | |
private var _binding: T? = null | |
protected val binding get() = _binding!! | |
final override fun onCreateView( | |
inflater: LayoutInflater, | |
container: ViewGroup?, | |
savedInstanceState: Bundle? | |
): View { | |
_binding = inflate(inflater, container, false) | |
return binding.root | |
} | |
override fun onDestroyView() { | |
super.onDestroyView() | |
_binding = null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment