ViewBindingEx
ViewBinding with Kotlin Property Delegate and Lifecycle, no memory leak
Install / Use
/learn @guyuuan/ViewBindingExREADME
ViewBindingEx
ViewBinding with Kotlin Property Delegate and Lifecycle, no memory leak
Usage
-
Add maven central to your project
repositories { ... mavenCentral() ... } -
Add the dependency in your App module
dependencies { implementation("cn.chitanda:viewbindingex:1.2.0") } -
Activity
class MainActivity : AppCompatActivity() { private val binding by viewBinding(ActivityMainBinding::inflate) override fun onCreate(savedInstanceState: Bundle?) { setContentView(binding.root) } }Fragment or DialogFragment
-
Use ViewBinding.inflate()
class HomeFragment : Fragment() { private val binding by viewBinding { FragmentHomeBinding.inflate(layoutInflater) } private val viewModel by viewModels<HomeViewModel>() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding.textHome.text = "hello world" } } -
Use ViewBinding.bind()
class HomeFragment : Fragment(R.layout.fragment_home) { private val binding by viewBinding (FragmentHomeBinding::bind) override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding.button.setOnClickListener { HomeDialog().show(childFragmentManager,"dialog") } } }
-
Related Skills
node-connect
353.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
353.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
353.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
