This course will be retired on July 14, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Android Fragments!
You have completed Android Fragments!
Preview
In this video we finally get to see our list!
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Now that we've finished our adapter,
0:00
let's head over to our list
fragment's layout file.
0:02
And give our adapter
something it can work with.
0:04
Let's head over to the Text tab and
start by deleting the TextView.
0:07
Then, let's add in
a RecyclerView to hold our list.
0:13
And since we waned to take up the whole
screen, let set its width and
0:20
height to match parent.
0:24
We also wanna be able to
access this view from code.
0:27
So let's give it an ID,
Of listRecyclerView.
0:30
Then I'll add a backslash here and
that will end the tag.
0:40
Great job.
0:45
Now it's a jump to our list fragment
class and hook up a recycler view.
0:46
First we'll need to get
a reference to our recycler view.
0:52
Let's add some space
below the inflater and
0:55
create a new recycler
view named recyclerView.
0:59
And let's set it equal to
view.findViewById.ListRecyclerView.
1:04
And then use ALT enter to add the cast.
1:15
Next, let's create a new variable for
our ListAdapter as well.
1:20
But first I'm going to give myself
a little more room on the right.
1:24
Back to the List Adapter.
1:29
ListAdapter, let's name it ListAdapter and
set it equal to new ListAdapter.
1:35
Now that we have our ListAdapter let's
attach it to a recyclerView by calling
1:42
recyclerView.setAdapter and
passing it on our listAdapter.
1:46
Next we need to set a layout manager for
our recyclerView.
1:54
Remember the layout manager is responsible
for determining where to place the views,
1:58
as well as when to reuse a view
that's no longer visible.
2:03
To make our recyclerView
act like a vertical list,
2:08
we can use the built in
linear layout manager class.
2:11
Let's create a new variable for
our layout manager named LayoutManager.
2:15
And let's set it equal to
new LinearLayoutManager.
2:23
And for
the context let's pass in getActivity.
2:29
Fragments always have access to their
activity through the getActivity method.
2:33
We also could have used to get context.
2:38
Now that we've got our layout manager.
2:41
Let's attach it to our
recyclerView By calling recycler
2:44
view.setlayoutmanager and
passing it in our layout manager.
2:47
That should do it.
2:56
Let's test the app and see what happens.
2:57
Nice.
3:07
We've got a list of all our recipes
including pictures, and it scrolls up and
3:07
down too.
3:11
Perfect.
3:14
But this white background
is awfully bright.
3:15
Let's change this By opening
our styles.xml file and
3:18
the resources directory,
under the values directory and
3:23
changing the parent theme to just
the standard, theme.appcompat.
3:28
Now if we run the app again.
3:35
Welcome to the dark side.
3:40
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up