Created
February 26, 2020 15:04
-
-
Save kakai248/4c743a78f16004e419bf737bd26c891e to your computer and use it in GitHub Desktop.
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 BaseFragment<VB : ViewBinding>( | |
private val bindingFactory: (LayoutInflater, ViewGroup?, Boolean) -> VB | |
) : Fragment() { | |
private var _binding: VB? = null | |
val binding: VB | |
get() = _binding!! | |
override fun onCreateView( | |
inflater: LayoutInflater, | |
container: ViewGroup?, | |
savedInstanceState: Bundle? | |
): View? = bindingFactory(inflater, container, false).also { _binding = it }.root | |
override fun onDestroyView() { | |
super.onDestroyView() | |
_binding = null | |
} | |
} | |
class ExampleFragment : BaseFragment<FragmentExampleBinding>(FragmentExampleBinding::inflate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment