Android Xml Views
ASecurityEnable ViewBinding in the module and use the generated binding class instead of looking up each view by ID: ```kotlin // app/build.gradle.kts android { buildFeatures { viewBinding = true } } ``` For a layout named `fragment_home.xml`, Android generates `FragmentHomeBinding`. Bind the Fragment's view in `onViewCreated`, use the binding only while the view exists, and clear it in `onDestroyView`: ```kotlin class HomeFragment : Fragment(R.layout.fragment_home) { private var _binding: FragmentHom...
- 584 stars
- 0 votes
- 0 copies
- 6 views
- Added September 5, 2026
Works with
Security analysis
100/100Pro scans all 18 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill android-xml-views --agent claude-codeAre you the author of Android Xml Views?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-android-xml-views-agent-skills-standard)# Use ViewBinding in the Fragment
Enable ViewBinding in the module and use the generated binding class instead of looking up each view by ID:
```kotlin
// app/build.gradle.kts
android {
buildFeatures {
viewBinding = true
}
}
```
For a layout named `fragment_home.xml`, Android generates `FragmentHomeBinding`. Bind the Fragment's view in `onViewCreated`, use the binding only while the view exists, and clear it in `onDestroyView`:
```kotlin
class HomeFragment : Fragment(R.layout.fragment_home) {
private var _binding: FragmentHomeBinding? = null
private val binding: FragmentHomeBinding
get() = checkNotNull(_binding)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
_binding = FragmentHomeBinding.bind(view)
binding.titleText.text = getString(R.string.home_title)
binding.retryButton.setOnClickListener {
// Handle the click.
}
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
```
This gives compile-time access to views, removes `findViewById` casts and nullability mistakes, and avoids retaining a destroyed Fragment view across the Fragment's view lifecycle. Do not keep `binding` in a long-lived object or use it after `onDestroyView`; use the Fragment itself for longer-lived state.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- trigger-1.md
- trigger-10.md
- trigger-11.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
- trigger-5.md
- trigger-6.md
- trigger-7.md
- trigger-8.md
- trigger-9.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.