Join Albert Lo for an in-depth discussion in this video Fragment for Side NavDrawer, part of Android Development: Modern Android UI Design Elements.
- [Instructor] Our private method, display Google Photos fragment, will do three things. First, it will set the title. Next, it will also start a new fragment, and we will call this method set fragment. We will pass in two parameters. The first parameter will be an instance of our Google Photos fragment.
And the second parameter will be the name of the fragment. Let's go ahead and create our private method, set fragment. Set fragment will take two parameters. First one is a fragment. And it will be a v4 fragment because jar layout requires v4 fragments. So I'm going to select the v4 fragment.
And I'm also going to specify a string parameter for the fragment name. So in this set fragment method, we are going to call get support fragment manager. And we will use that to start our new fragment. We will use the replace method to start our new fragment. The container view ID will be something that we have to define.
And the other parameters will be ones that are passed in in this method, fragment and fragment name. We need to verify this resource ID named content layout. So let's go into our activity main, and let's go into app R main by pressing Control + B. And let's go into content main by pressing Control + B. There's a couple of things we need to verify. First one is that we have the correct resource ID.
Content layout is there. The other one is that we need to add a view ID to this text view. So let's go ahead and do that. We're going to call it placeholder text. Now let's switch back to our main activity. We're going to scroll into our inflate views. And now we're going to add some code to find our view for the placeholder text.
I'll call the find view by ID method. And we'll pass in the placeholder text view ID that we just defined in content name. Now we're going to convert this placeholder text to a class member as well. So I'm going to press Command + X to cut and insert it at the top of the class. It will be a private class member. And I press Control + V to paste.
Now I copy my placeholder text variable name with Command + C. I'm going to go back down and paste it in into my inflate views. Now I have access to it. I'm going to scroll to the bottom, and I will use it in display Google Photos fragment method. Here, I'm going to hide my placeholder text by calling this set visibility. And I change the visibility mode to invisible.
The Google Photos fragment, you will leave this undefined for now. And in the next video, we're going to look at how to create a Google Photos fragment.
- Creating a custom layout with XML
- Setting up OnClick handlers
- Making API calls
- Creating custom views
- Implementing ViewHolder objects
- Signing certificates
- Adding a checkbox