Android Xml Views
ASecurityUse `ListAdapter`, which wraps `AsyncListDiffer`, and describe how items are identified and when their contents changed. Submit each new snapshot with `submitList()`: ```kotlin data class Post( val id: Long, val title: String, ) class PostAdapter( private val onClick: (Post) -> Unit, ) : ListAdapter<Post, PostAdapter.ViewHolder>(DIFF_CALLBACK) { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { val binding = ItemPostBinding.inflate( LayoutInflater.from(parent.con...
- 584 stars
- 0 votes
- 0 copies
- 2 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-57b46013)# Replace `notifyDataSetChanged()` with `ListAdapter`
Use `ListAdapter`, which wraps `AsyncListDiffer`, and describe how items are identified and when their contents changed. Submit each new snapshot with `submitList()`:
```kotlin
data class Post(
val id: Long,
val title: String,
)
class PostAdapter(
private val onClick: (Post) -> Unit,
) : ListAdapter<Post, PostAdapter.ViewHolder>(DIFF_CALLBACK) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val binding = ItemPostBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false,
)
return ViewHolder(binding)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(getItem(position))
}
inner class ViewHolder(
private val binding: ItemPostBinding,
) : RecyclerView.ViewHolder(binding.root) {
fun bind(post: Post) {
binding.title.text = post.title
binding.root.setOnClickListener { onClick(post) }
}
}
companion object {
private val DIFF_CALLBACK = object : DiffUtil.ItemCallback<Post>() {
override fun areItemsTheSame(oldItem: Post, newItem: Post): Boolean =
oldItem.id == newItem.id
override fun areContentsTheSame(oldItem: Post, newItem: Post): Boolean =
oldItem == newItem
}
}
}
```
Update the adapter with a new, preferably immutable list:
```kotlin
adapter.submitList(postsFromRepository)
```
`areItemsTheSame` answers whether two rows represent the same entity; `areContentsTheSame` answers whether that entity's rendered content is unchanged. `ListAdapter` computes the difference asynchronously and dispatches only the required insert, remove, move, and change operations, so there is no need for—and you should not call—`notifyDataSetChanged()`. Avoid mutating a list after submitting it; create a new snapshot when items change.
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.