Skip to content

Instantly share code, notes, and snippets.

@aloj22
aloj22 / ViewBindingExtension.kt
Created Feb 28, 2022
View binding lazy initialization for Fragment/Activity
View ViewBindingExtension.kt
import android.app.Activity
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding
inline fun <reified T : ViewBinding> Activity.viewBinding(
parent: ViewGroup? = null,
attachToParent: Boolean = false,
): Lazy<T> {