RecyclerView Basics Flashcards
What is the role of a RecyclerView Adapter?
- Adapts a list so the RecyclerView can display its items
2. Produces ViewHolders
What does a ViewHolder contain?
- Views
- Data
- Meta information
How does the RecyclerView know how many items to display?
getItemCount() in the Adapter
Which two Adapter methods bind ViewHolders to data?
onCreateViewHolder()
and
onBindViewHolder()
What 6 parts are required for a RecyclerView?
Data to be displayed RecyclerView Instance in layout xml Item layout xml Layout Manager ViewHolder Adapter
How are Views presented in the provided LinearLayoutManager?
A vertical list of full width rows
Which 3 LayoutManagers are suggested by Android Studio?
LinearLayoutManager
GridLayoutManager
StaggeredGridLayoutManager
What is the core task in implementing a RecyclerView?
Creating the Adapter
Which 3 functions must be implemented in the Adapter?
onCreateViewHolder()
onBindViewHolder()
getItemCount()
What will the functions in the Adapter be called by?
The RecyclerView
What parameters are taken by onCreateViewHolder() ?
parent: ViewGroup (the RecyclerView)
viewType: int
What is the role of the LayoutInflater?
It creates a View from a layout xml
What is the syntax for creating a LayoutInflater?
val layoutInflater = LayoutInflater.from(parentView.context)
Why is attachToRoot false when inflating a View?
Attaching the child View to its parent is not the responsibility of onCreateViewHolder()
Which 3 parameters are passed to LayoutInflater.inflate() ?
- The layout xml to be inflated into a View
- The parent View to which this (return, child) View will be attached
- attachToRoot: Boolean