RecyclerView, DiffUtil & XML Layouts Interview Questions
UI › Views & RecyclerView
How does RecyclerView work, and what does a ViewHolder do?
What a strong answer covers: RecyclerView only creates enough item views to fill the screen plus a few extra, and recycles views that scroll off for new items. The Adapter creates ViewHolders (onCreateViewHolder) and binds data into them (onBindViewHolder). A ViewHolder caches references to its child views so binding doesn't call findViewById each time. The LayoutManager decides positioning.
What is DiffUtil, and why use ListAdapter instead of notifyDataSetChanged?
What a strong answer covers: notifyDataSetChanged rebinds everything, loses animations and scroll anchoring. DiffUtil compares old and new lists with areItemsTheSame (same identity, usually id) and areContentsTheSame (same data) and sends minimal insert, remove, move and change updates. ListAdapter with AsyncListDiffer runs the diff on a background thread; you just call submitList with a new list.
What are the common causes of RecyclerView scroll jank?
What a strong answer covers: Heavy work in onBindViewHolder (formatting, parsing, synchronous image decoding), deep or complex item layouts, inflating views inside bind, setHasFixedSize not set when it could be, nested RecyclerViews without shared view pools, notifyDataSetChanged on every update, and large images without proper sizing. Use the profiler and systrace to find which part of the frame is slow.
How would you build a list with several view types, and where does payload-based partial binding help?
What a strong answer covers: Override getItemViewType to return a type per item, create the matching ViewHolder per type, and model items as a sealed class. ConcatAdapter can combine separate adapters (header, items, footer). Payloads: return a change payload from getChangePayload in DiffUtil, and in onBindViewHolder(holder, position, payloads) update only what changed, like a like count, avoiding a full rebind and change animation flicker.
How would you migrate a large RecyclerView-based screen to Compose incrementally, and what interop pitfalls are there?
What a strong answer covers: Start by rendering individual items with ComposeView inside ViewHolders, setting ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed (default since Compose 1.2 handles recycling better), then replace the whole list with LazyColumn once the items are composables. Pitfalls: composition cost per recycled item, lifecycle and composition disposal in recycled views, nested scrolling between Views and Compose, theming bridges, and test tooling for both. Measure scrolling before and after.