Skip to content
Back to skills

Android Xml Views

ASecurity

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: FragmentHom...

  • 584 stars
  • 0 votes
  • 0 copies
  • 6 views
  • Added September 5, 2026
developmentkotlin

Works with

  • cli

Security analysis

A100/100

Pro scans all 18 files and shows the line behind each finding

Scanned September 5, 2026

npx -y skills add HoangNguyen0403/agent-skills-standard --skill android-xml-views --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Android Xml Views?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Android Xml Views
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hoangnguyen0403-android-xml-views-agent-skills-standard/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-android-xml-views-agent-skills-standard)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# 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.md1.7 KB
  • eval-1.with-skill.md1.4 KB
  • eval-2.baseline.md2 KB
  • eval-2.with-skill.md2 KB
  • eval-3.baseline.md2.3 KB
  • eval-3.with-skill.md2.3 KB
  • trigger-1.md124 B
  • trigger-10.md137 B
  • trigger-11.md129 B
  • trigger-2.md120 B
  • trigger-3.md122 B
  • trigger-4.md129 B
  • trigger-5.md107 B
  • trigger-6.md115 B
  • trigger-7.md149 B
  • trigger-8.md152 B
  • trigger-9.md134 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.