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'll create the directions Fragment!
This video doesn't have any notes.
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
We've just finished the ingredients
fragment can you guess what's up next?
0:00
And that's right the directions fragment.
0:04
And if we take a look at the mock
ups it doesn't look like there's
0:06
anything new here.
0:09
So if you think you can handle finishing
up the directions fragment, go ahead and
0:10
pause me and give it a shot.
0:14
If you'd rather follow along as I
finish up the directions fragment.
0:17
Then here we go.
0:20
Let's start.
0:21
But updating fragment
directions dot X.M.L..
0:22
First.
0:26
Well delete the text view.
0:26
Then.
0:29
Will give our linear layout
an id of directions layout.
0:30
Android.
0:33
Id directions layout.
0:35
Lastly.
0:42
Let's add a scroll view
around our linear layout.
0:44
Just like we did in the previous video.
0:47
Scroll view.
0:48
Give it the same width and height,
and a copy of the closing tag or
1:03
cut the closing tag down to the bottom.
1:09
Nice.
1:16
Now let's switch over to our ViewPagerFragmentClass and
1:17
pass an index we need to
our directions fragment.
1:20
We can do this and the same way as
we did for our ingredients fragment.
1:24
Let's copy this bundle bit
excluding the bundle keyword,
1:28
and then paste it below
are directions fragment.
1:31
Then let's replace Ingredients
fragment with directions fragment.
1:37
And cool, all that's left now are the
changes to the directions fragment class.
1:44
Let's start by retrieving
the index argument
1:51
into a new int variable named index.
1:54
and index equals getArguments.getInt
1:56
ViewPagerFragment.KEY_RECIPE_INDEX.
2:02
Then, below where we set our view, let's
create a new linear layout variable for
2:08
our directions fragment.
2:13
>> [SOUND]
>> Linear layout.
2:14
Call it linear layout equals
2:19
view dot findview I D R dot
I D dot directions layout.
2:22
And then Alt+Enter to add the cast.
2:27
And then below that, let's create
a string array to hold the directions for
2:32
this recipe.
2:36
String array named directions
2:36
equals recipes.directions.
2:41
At position [index].split.
2:46
And split based on where
the back take character is.
2:53
Now that we've got the directions
layout and the directions themselves.
2:58
This class doesn't really differ
too much from ingredients fragment.
3:02
So for the rest of this let's just copy
and paste from ingredients fragment.
3:06
Let's start with the variables.
3:10
Then let's copy over the rest
of the onCreatView method.
3:23
Starting with mCheckBoxes,
3:27
And replace Ingredients with directions.
3:35
And finally,
let's copy over the setUpCheckBoxes, and
3:39
on savedInstanceStateMethods.
3:42
And change ingredients to directions here,
as well.
3:54
That should do it.
4:14
Now let's test the app.
4:16
And hopefully will see some directions
to go along with our ingredients.
4:17
Perfect.
4:30
Now I can really start my morning
right with a nice delicious muffin.
4:31
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