Junior — Middle
Have you worked with a component that displays a list of items?
sobes.tech AI
Answer from AI
In Android, components like RecyclerView or ListView are commonly used to display lists of items.
- RecyclerView is a more modern and flexible component that efficiently reuses list items to optimize performance.
- ListView is an outdated component that is simpler but less efficient.
Example of using RecyclerView:
- Create an adapter that binds data to list items.
- Set up a LayoutManager (e.g., LinearLayoutManager for a vertical list).
- Assign the adapter and LayoutManager to the RecyclerView.
val recyclerView = findViewById<RecyclerView>(R.id.recyclerView)
recyclerView.layoutManager = LinearLayoutManager(this)
recyclerView.adapter = MyAdapter(myDataList)
Thus, RecyclerView allows for efficient display of large lists with customizable elements.