Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,000 --> 00:00:05,295
Displaying a list of data is one of the most common UI tasks in Android.
2
00:00:05,295 --> 00:00:08,595
In a weather app, you might show a list of forecasts.
3
00:00:08,595 --> 00:00:12,210
In a chat app, you will show a list of chat messages.
4
00:00:12,210 --> 00:00:15,705
In a news app, you will show a list of news items.
5
00:00:15,705 --> 00:00:18,180
If you look at the apps on your phone,
6
00:00:18,180 --> 00:00:22,005
almost every single app has at least one list.
7
00:00:22,005 --> 00:00:27,555
List vary from a simple list of TextViews that show simple data,
8
00:00:27,555 --> 00:00:33,840
to very complex items that show the user lots of details inside the scrolling list.
9
00:00:33,840 --> 00:00:38,109
Some apps even use a list as their main user interface,
10
00:00:38,109 --> 00:00:41,480
displaying complex summaries for the user to browse.
11
00:00:41,480 --> 00:00:46,670
Some apps use a grid to show a lot of elements in a compact form.
12
00:00:46,670 --> 00:00:51,950
This is a really good pattern that you can communicate effectively with icons or images,
13
00:00:51,950 --> 00:00:53,915
like a photo browsing app.
14
00:00:53,915 --> 00:00:56,450
To support all these use cases,
15
00:00:56,450 --> 00:00:59,420
android comes with the RecyclerView widget.
16
00:00:59,420 --> 00:01:06,305
RecyclerView is designed to be efficient even when displaying extremely large lists.
17
00:01:06,305 --> 00:01:10,340
It allows you to build everything from simple lists of
18
00:01:10,340 --> 00:01:15,505
TextViews all the way to very complex collections of views.
19
00:01:15,505 --> 00:01:20,165
It only support displaying different types of items in the same list.
20
00:01:20,165 --> 00:01:26,420
For example, a news app may want to mix video items into a list of headlines.
21
00:01:26,420 --> 00:01:30,040
RecyclerView is also highly customizable.
22
00:01:30,040 --> 00:01:33,890
Out-of-the-box, it supports lists and grids.
23
00:01:33,890 --> 00:01:38,495
You can configure it to scroll horizontally or vertically.
24
00:01:38,495 --> 00:01:40,640
If the default options aren't enough,
25
00:01:40,640 --> 00:01:43,580
you can even build your own layout manager to make
26
00:01:43,580 --> 00:01:46,920
RecyclerView display any design you dream up.
27
00:01:46,920 --> 00:01:49,640
RecyclerView is efficient in a few ways.
28
00:01:49,640 --> 00:01:51,515
It uses an adapter pattern,
29
00:01:51,515 --> 00:01:54,290
which we will talk about in the next video,
30
00:01:54,290 --> 00:01:57,715
to minimize the work it does when drawing a list.
31
00:01:57,715 --> 00:02:00,620
By default, it will only do work to
32
00:02:00,620 --> 00:02:04,730
process or draw items that are currently visible on the screen.
33
00:02:04,730 --> 00:02:10,515
That means, if your list has 1,000 elements but only 10 are visible,
34
00:02:10,515 --> 00:02:12,800
it will only do enough for it to draw
35
00:02:12,800 --> 00:02:17,105
the first 10 items on screen until the user scrolls.
36
00:02:17,105 --> 00:02:19,040
When the user scrolls,
37
00:02:19,040 --> 00:02:22,760
RecyclerView will figure out what new items should be
38
00:02:22,760 --> 00:02:26,435
on screen and to just enough work to display those.
39
00:02:26,435 --> 00:02:27,860
What's really nice is,
40
00:02:27,860 --> 00:02:30,860
you don't have to do anything to get this behavior.
41
00:02:30,860 --> 00:02:33,645
It comes by default in RecyclerView.
42
00:02:33,645 --> 00:02:41,135
Another way that RecyclerView is efficient is by reusing or recycling as much as it can.
43
00:02:41,135 --> 00:02:44,680
When an item scrolls off the screen, it's recycled.
44
00:02:44,680 --> 00:02:47,420
That means, it will reuse the views it
45
00:02:47,420 --> 00:02:51,440
allocated for the next item that will scroll onto the screen.
46
00:02:51,440 --> 00:02:55,340
It turns out this saves a lot of processing time,
47
00:02:55,340 --> 00:02:58,855
and it helps making sure your list scroll fluidly.
48
00:02:58,855 --> 00:03:02,290
Finally, when an item changes in RecyclerView,
49
00:03:02,290 --> 00:03:04,670
instead of redrawing the entire list,
50
00:03:04,670 --> 00:03:07,790
it just updates that one single item.
51
00:03:07,790 --> 00:03:12,550
This is a huge efficiency gain when displaying lists of complex items.
52
00:03:12,550 --> 00:03:15,560
Recycling as much as possible is key to
53
00:03:15,560 --> 00:03:18,980
making RecyclerView efficient that it's part of the name.
54
00:03:18,980 --> 00:03:20,690
As you'll see in this lesson,
55
00:03:20,690 --> 00:03:24,455
RecyclerView is designed to do this recycling for you.
56
00:03:24,455 --> 00:03:27,710
You don't have to do anything to enable the recycling,
57
00:03:27,710 --> 00:03:33,050
but it does mean you need to be aware that your views will get re-used.
58
00:03:33,050 --> 00:03:36,750
If you don't use the RecyclerView API correctly,
59
00:03:36,750 --> 00:03:41,200
you can extently show old items when the views are reused.
60
00:03:41,200 --> 00:03:44,705
Here, you can see one view that has been filled
61
00:03:44,705 --> 00:03:48,365
and it keeps getting reused by the RecyclerView.
62
00:03:48,365 --> 00:03:51,050
Instead of getting reset when recycled,
63
00:03:51,050 --> 00:03:54,920
it's keeping to fill and showing it on the next item.
64
00:03:54,920 --> 00:03:57,740
We'll talk later in this lesson about how to
65
00:03:57,740 --> 00:04:00,860
use RecyclerView properly when your view is recycled.
66
00:04:00,860 --> 00:04:04,595
RecyclerView, while efficient and customizable,
67
00:04:04,595 --> 00:04:08,450
is not the only way to display a list of things on Androids.
68
00:04:08,450 --> 00:04:13,490
Android also ships with a few other options for displaying lists.
69
00:04:13,490 --> 00:04:16,610
The first are ListView and GridView
70
00:04:16,610 --> 00:04:20,705
for displaying a scrolling list and grid respectively.
71
00:04:20,705 --> 00:04:24,290
You can think of this as RecyclerView simpler,
72
00:04:24,290 --> 00:04:26,960
but less powerful siblings.
73
00:04:26,960 --> 00:04:30,230
Both of them work for displaying a small list of
74
00:04:30,230 --> 00:04:34,220
items that aren't too complex, like 100 items.
75
00:04:34,220 --> 00:04:37,220
They are not nearly as efficient as RecyclerView,
76
00:04:37,220 --> 00:04:42,595
and they don't offer nearly as many options for customizing the display.
77
00:04:42,595 --> 00:04:46,280
In general, the increased performance and flexibility
78
00:04:46,280 --> 00:04:50,180
of RecyclerView makes it a better choice for your app.
79
00:04:50,180 --> 00:04:52,745
The other option is LinearLayout.
80
00:04:52,745 --> 00:04:55,625
You've already seen that earlier linear layout
81
00:04:55,625 --> 00:04:58,655
can be used to display a small list of items,
82
00:04:58,655 --> 00:05:00,680
for example three to five.
83
00:05:00,680 --> 00:05:05,270
But using something as powerful as an RecyclerView is not needed.
84
00:05:05,270 --> 00:05:11,300
However, if you aren't sure that you will ever need to display more than a few elements,
85
00:05:11,300 --> 00:05:13,610
RecyclerView is a better choice.
86
00:05:13,610 --> 00:05:19,525
In this lesson, you will take the sleep tracker app and update it to your RecyclerView.
87
00:05:19,525 --> 00:05:24,440
Last lesson, we'll retrieve and display the scrollable text on-screen.
88
00:05:24,440 --> 00:05:26,400
But wait a minute.
89
00:05:26,400 --> 00:05:28,355
That doesn't look really nice.
90
00:05:28,355 --> 00:05:32,775
The printed concatenated text is very hard to format.
91
00:05:32,775 --> 00:05:37,250
We had to provide a whole pretty complex formatter for it,
92
00:05:37,250 --> 00:05:40,775
and it's almost impossible to have a nice layout design.
93
00:05:40,775 --> 00:05:44,300
For example, we have to show the qualities and number,
94
00:05:44,300 --> 00:05:46,880
and it would look much better as an icon.
95
00:05:46,880 --> 00:05:52,615
Finally, it definitely won't scale as our data grows and changes.
96
00:05:52,615 --> 00:05:55,790
In this lesson, we'll use a recycler view to
97
00:05:55,790 --> 00:05:59,485
show all the sleep data as a simple list like this.
98
00:05:59,485 --> 00:06:02,980
You will implement each part of a RecyclerView,
99
00:06:02,980 --> 00:06:06,035
and we will explain how it works as we go along.
100
00:06:06,035 --> 00:06:08,810
Once you have a working app with a list,
101
00:06:08,810 --> 00:06:12,545
we'll change gears and display the sleep data as a grid.
102
00:06:12,545 --> 00:06:15,680
This is another way to represent the same data,
103
00:06:15,680 --> 00:06:22,160
and we'll see how our RecyclerView architecture helps us easily make updates like this.
104
00:06:22,160 --> 00:06:24,155
At the end of this lesson,
105
00:06:24,155 --> 00:06:29,055
you'll be comfortable using RecyclerView for both lists and grids.
106
00:06:29,055 --> 00:06:31,850
In addition, you will have an understanding of
107
00:06:31,850 --> 00:06:35,260
the adapter pattern used by the RecyclerView.
9177
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.