Difficulty: Medium
Correct Answer: A custom Adapter class that inflates a custom row layout for each list item
Explanation:
Introduction / Context:
Android applications often show lists of options, such as multiple choice questions, contact lists, or menus. The framework provides standard list item layouts, but many real applications require custom appearances, for example with images, multiple text fields, or check boxes. To achieve this, developers need more than a basic ListView or RecyclerView declaration. They must connect the list component to a custom Adapter that inflates a custom layout for each row. This pattern is a common interview topic for Android developer roles.
Given Data / Assumptions:
We want a multiple choice list where each row has a custom view layout.We are working within the Android user interface framework using components such as ListView or RecyclerView.The question asks what is needed to make this custom row view approach work.We assume that options like Intent or Toast are familiar but have different responsibilities.
Concept / Approach:
In Android, a list control such as ListView or RecyclerView does not know by itself how to display each item. Instead, it delegates that responsibility to an Adapter. A custom Adapter extends a base class such as BaseAdapter, ArrayAdapter, or RecyclerView.Adapter and overrides methods that create and bind views. Inside these methods, the adapter inflates a custom XML layout for each row, sets text or images, and returns the finished view. This pattern allows developers to create rich multiple choice list items with radio buttons or check boxes, icons, and styled text, all while reusing view objects for performance.
Step-by-Step Solution:
First, identify the task: building a multiple choice list where each row has its own custom layout.Next, recall that ListView and RecyclerView rely on adapters to provide views for each row or item.Then, remember that a custom Adapter class can inflate any XML layout you design for the list row and bind data to it.After that, compare this requirement with the answer options and see which one specifically mentions a custom Adapter that inflates custom row layouts.Finally, conclude that option A is correct because it describes the standard Android solution for custom row views in lists.
Verification / Alternative check:
Every official and community Android tutorial that demonstrates custom list items uses an adapter subclass. Code examples show overriding getView for ListView or onCreateViewHolder and onBindViewHolder for RecyclerView, with calls to LayoutInflater.inflate to create row views from XML. Intents, BroadcastReceivers, and ContentProviders are used for other purposes such as navigation, system event handling, and data sharing, not for drawing individual list rows. This consistent pattern across many examples verifies that the custom Adapter is the key requirement.
Why Other Options Are Wrong:
Option B mentions an Intent, which is used to start activities or services but does not manage row layouts in lists. Option C uses a BroadcastReceiver, which responds to broadcast messages and is not responsible for rendering user interface elements. Option D refers to a ContentProvider, which exposes data to other components but does not automatically turn tables into custom visual rows. Option E focuses on a Toast message, which is simply a small notification and does not influence how list items are drawn.
Common Pitfalls:
New developers sometimes try to modify list row layouts directly in activities instead of through an adapter, which leads to duplicated code and poor performance. Another common mistake is inflating a new view each time without reusing convertView in ListView or using view holders in RecyclerView, which can cause lag when scrolling. By understanding that the correct approach is to use a custom Adapter that inflates and reuses custom row layouts, developers can build efficient and flexible multiple choice lists that meet real design requirements.
Final Answer:
The correct answer is: A custom Adapter class that inflates a custom row layout for each list item.
Discussion & Comments