Skip to content

Commit 7323aab

Browse files
committedOct 30, 2019
RecyclerView review doc
1 parent c1a9137 commit 7323aab

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
 

‎RecyclerViewReview.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# RecyclerViews
2+
3+
## The Key Players
4+
5+
* The **RecyclerView** is provided by Android. It's the class responsible for actually handling moving the individual rows of the view around as the user scrolls.
6+
7+
* The **Adapter** is a class we write that tells the RecyclerView how to behave. It does so through the three methods that have to be overridden:
8+
* `onCreateViewHolder` will be called by the RecyclerView whenever it needs to create a brand-new row of the table. In that method, our Adapter will create that view by inflating a layout file, and it will put that view inside of a ViewHolder (see below) that it returns to the RecyclerView.
9+
* `onBindViewHolder` will be called by the RecyclerView whenever it wants to take a particular ViewHolder (that we created in a previous call to onCreateViewHolder) and prepare that ViewHolder to be displayed at a particular index of the RecyclerView. In that method, our Adapter will fill in the ViewHolder with the data that should be displayed at that index.
10+
* `getItemCount` will be called by the RecyclerView when it's trying to figure out how many total rows it might need. In that method, we return... how many rows there should be.
11+
12+
* The **ViewHolder** is a class we write to act as a wrapper around the actual widgets on the page that will be displayed. Our main job is, in the constructor, to save references (as instance variables) to each of the individual views that we'll want to change for each row of the table. We can then use those instance variables within the `onBindViewHolder` method of our Adapter.
13+
14+
## Some Other Related Concepts
15+
16+
* In order to allow users to tap on the rows of our RecyclerView, within the constructor for our ViewHolder, we add an onClick listener to the entire row that will notify the Activity that contains the RecyclerView about which row was tapped on.

0 commit comments

Comments
 (0)