 All right, so the next part is I'm going to show you how to create a list fragment. So let's create another fragment here. It'll be similar to the regular fragment or call it work list fragment. So here is the same assembly function we saw earlier looks exactly same as before. So I'm going to just in the class this I don't need all these here. Now this list fragment must extend not the fragment but the list fragment. So now and then all you need here is really two functions. One is the unattach. Remember that when you attach the list to the activity, you need to know that, right? So where it's been used in our case, we're going to attach it to the main activity here. So that we have the list view show in the main activity when we run the app on the main page. I want to see on the main page, right? I want to see the list of activities here but we're not using a list view using a list fragment. When I click on a particular item, it's going to jump over to the email page and then list the detail information here. Okay, so that's what we're going to load but go back to the work list fragment. So you need the unattach function. If you just hit enter here and then you also need the upgrade view. And so before we return that back to the container, you want to do some processing here. Okay, so in here you're going to create an interface. The interface is either a part of this fragment. Usually it is if it's only working in this fragment here. You can put it inside here or you can put it outside. It doesn't matter, okay? But you can put it inside here in the class space. And this has to be set to public and static so you can access it. I don't think any public can just say static should be fine. Enter face and then what do you want to call this one here? You can call it this listener. It listens to events. We're going to create just one function where you click an item on the list if you call it the item click. So void item click. It's common and when you click on this function, we're going to pass into this function in ID. The ID here is the position of that list. So whoever uses interface must implement this function. So here again, I put inside here. If it's confusing, you can put it outside like this. It's okay too. Once you put outside, you can put static here. You can put outside for now. You can understand that better. You want to separate these. Usually you put into a separate class, right? But it's so simple. I'll just leave it here. So inside here then, I'm going to create a private listener object called the same thing. Okay. So it's pointing to this class here, an object of that type. And so somewhere I have to inject the activity object to this class so you can use it. Okay. So where do you do that? You do that when you attach to an object. The context, context. So this context is the object of wherever it's coming from, whichever activity is. So if I'm using the main activity, it'll be the main activity object. If I call it from the work activity, it'll be that. So inside here then, I'm going to set this listener to that context. And you want to convert to the same type because again, just object. So I'm assigning this object here, wherever it's coming from, I don't care, right? I don't need to know. I assign that to this listener here so that I can invoke this objects function. Okay. So now a pause here. Now let's go over to the other side. I'm going to list my view on this activity page here. So my main page, what do I have? I'm going to create a function that's the main activity. Yeah. So create a function somewhere down here, such that when I click on an item, I'm going to call the function item click. What do you call? Yeah. Item click. I need to implement this interface. Okay. So over here, I'm going to add here, implements the interface called listener. So now you can see I'm forced to create or implement that function called item clicked. It's okay. And there it is. This is the function I need to implement. So when I click on this icon, this function here, what do I need to do? I want to pass in the item that's selected from the list. This ID is that ID. I'm going to pass it over to the workout activity. Okay. So instead of going to the button, go directly there this way. I'm going to send it off to use this same part here. I'm going to start the activity, put this here for now. I'm in the same class. So that's this destination. But I also want to get an ID. This ID here. Pass this ID along to the workout activity so it knows how to use it. So the workout activity, what does it do? Well, if you look out over here, right, we need to pass an ID to the fragment here. I manually insert a three and one here. I don't want to do that. I want to pass in here a number that's been passed over from this main activity. And that is this ID here. Okay. So before I start the activity over here, in this case, I can't do it this way because I need to create the intent. So let's take this out. Sorry. Let's do back here again. It'll be intent. We'll pass the intent here. The reason why is because I need to pass that ID over. So intent that put extra. Remember that one? So you put an ID here. Let's put here work ID or pass in the ID here. Okay. So that goes over. And then we start activity on the activity side. I want to get to the activity page. I need to retrieve the activity, right? So I would just do here and ID equal to and you get the, you get the int from get intent dot get int extra because then I'm using integer and it takes two things. The name is called work underscore ID. And if that doesn't match, the default will be zero. Okay. So now I got that ID. Then I pass this ID to that fragment, right? This will be the same one. I'm not going to do it. Let me, let me turn off this one here. Yeah. It's confusing. Let's, let's turn this off. I don't need the second one. Someone I just removed that one. Okay. The activity work out. So let's remove the second one. Just be one. Okay. So I pass that ID over to the fragment object. What an ID is over here. It should be the same as before. Just get the ID. You pass it here. Right. And then we'll display that information here. I'm only setting the title here. Okay. So again, we're still for the main activity. One item is clicked. We call this function. You pass ID here. But how does it know what to click, where to do that? Well, the clicking part is done inside the fragment list. Right. It doesn't hear. So in here then, I need to do something to make that work. And to make it work, if you remember, we set, remember we set like an adapter to, you know, load a listener and then load that to the list and so forth. So the list here, we need to, we need to populate the list first with the data. So let's see. I need to get the data from the work class. So let's do right here. We're just going to first get the name of that list. So put, the name will be just string, right? Yeah. We just get the name of the list or display this name to the list fragment. Okay. This is like the list view. So we will just build the list. So I need to get that from the names. They're coming from the work out that works for the work, get works either one. Sorry, no, I'm going to set the array first. Spring type and the size of this will be the workout. So the work out that works object, work else object. All right. And then we'll get the length of that. We'll tell you how many, you know, how many content we have inside the workouts array. And I'm going to put the name here. So this just tells me the size of the array. And I know we guys only create five because we only have one, two, three, four, actually only four, but we don't know that. It could be more or less. So it's actually better to find the length of that. And if this is confusing, you always do this. Okay. And then put here the spring of 11. Right. And then now I have to populate this list of names with the actual text. So you have to use the full loop in here, zero, I let's then the length and then I plus plus. And then I'm going to set the names of each position to the workout that works of I mean, sorry, workout of I that get the name, right? Object. Okay, you can do that. Or another way is what you can call the function that works. And then of I, okay, because I we made both of them. So either one will be fine. I will stay with this one here since we made it public anyway. So now we probably the names you put all those names, there are five of them. And then now we need to display to the view. Where is this going to go? Well, we're going to populate this view here to the main page. Okay, the main activity here. So that means in the main activity right here, we're going to add a list view back in here. Okay, so it'll be the fragment. I mean, at least I'm sorry, the fragment here. The width will be the rapid content. No, the width, I want the parent, rapid parent, match the parent, sorry. And then the height will be the rapid content, you don't want it, you don't want it to the whole space. And then you need an ID as well. The ID will be ID of fragment, frag list. And then where does this coming from? So it's coming from the name. This fragment is coming from the detail, the work list, okay. So now we link this fragment and the main layout to the work list fragment. So we need to populate this fragment here with the content here. Now we gather the data we want. We now need to populate the list fragment. So how do we do that? Well, we use the adapter. So let's say set list adapter, just like before, set list, like before we did a list view. And then here we're going to new array adapter. It's the same one we used before. And then the type in the bracket here will be the type of what this one is. It's strings, right? So it's composed of only strings and that's what we want. The end part here, three things. We need the contact. Where is it going? So in this case, you just have to remember this, okay. Inflator.getthicontext, the first thing. And then here is the layout that we need is the Android simple one. Android.r.layout.simple one, okay. Just a single list. And let me just move into a separate line. It's easier. And then the third one is what data should we populate with? Is this variable here? That is the array list of information you want to fill to that list. Okay. So this part here, it does support. It populates it for us. And I think that you can do it for now. But that's test first, okay. I'm not going to implement the feature yet. I want to make sure that it's actually loads of content. Okay, here we go, right? So our main fragment activity, we have the button, which is this guy up here, it's still functional because we said earlier. And there is the list view of the fragment view. Now this is not functional yet because we haven't done it yet. But you see that we fill up this fragment with the data from this class called work list fragment. And this page, we don't really care about this ID here. Notice that we didn't mention this at all in the list here. It knows it already because we already mentioned that. So we get the data from the database class. We get all the names only. And then we populate the list using the adapter, array adapter. This automatically inflates the data and the view as well, the list view. And then it populates the view, the list view in this case, with the names on the list. And now they're here. And so now the next thing is when I click on one of these items, what should it go? What should it do? Okay. So now, okay, I'm going to go and create the function on, I think on list item, item, yeah, this one here, on list item click. So this is an overloaded, overrided method. This one here runs automatically for you. You don't have to create listeners for that. Remember that I didn't have to attach, find the ID where that is. I don't have to because it manages directly by this guy right here. And he knows this is where it's going to go. Okay. So I don't have to set even listeners which one is click. It does automatically for you behind the scene because of this list fragment class. Okay. So I just call this function. It happens automatically. And then the L here is the list view. This list view here. The view here is the actual view itself. The list view has information. The position, as you can see, is the position of the index and ID of that as well. So when I get to this page, I'm clicking one item at a time. So I know exactly which one. Which one is it? Well, this one, right? So I don't have to check which one is which is which. It's already given here because we have access to the listener up here. Remember this listener? This listener is actually listening to this object, the main activity. So the main activity class has a function called item clicked because they both share the same interface. Listener. So now this fragment knows, I mean, it doesn't care who is invoking this. All it knows is that it attaches that to the listener object up here. So here, then I just basically listener dot this item click function right here. And it needs an ID. Well, there's the ID here. So this one, either one is fine. If you pass in the ID, then you have to convert it to an int. If you use position, then you don't have to. So I use position here because it matches the other side. So this function here now is really the main activities function here. So it takes an integer. So the ID comes here, and then it passes the ID over to the work activity. And then the work here gets that ID back here. And then it adds that to the fragment. So that's safe. And let's see what happens here. I want to click on the strength in length. You see it's a strength in length. Just make sure we go back and click on the coragony. Okay. And then and so on. So that's how list fragment works. So in this case, I don't care who it is. I don't need to know. All I know is I'm attaching that to the listener in the context here. So if it's coming from, you know, that activity, super activity, whatever activity is, then the listener is always that object. And because they're using the same listener interface, when you click it down here, it's going to invoke that object's function anyway. So this way is the better way because, again, you make it very flexible. It works with any case. Now the old way we used to do is this. Instead of going to this listener object, I would do intent, right? New intent. I mean, intent. Just like before, new intent. What I need to pass here, what I need to pass in the context. What context? Well, let me import this first. Context is the view here. If you look at the main one, we'd say this, right? This is the main activity. So the work list, the view here is this activity. So you put here, go to the view, the v.getContext. That is the context that we're going to coming from because, again, the fragment does not have, it doesn't exist by itself, so it needs the actual parent or the actual activity's object here. And then the destination is going to go to the detail fragment. No, no. The work out activity, I'm sorry. The work out activity.class, right? This is something you're already very familiar with. And then after you set the ID, intent.put, extra, and then work ID, the same ID as the other side has to match. I'm going to pass in the position, and then I'll start activity. Pass in the intent. This is something you're already very familiar with, right? This will work, of course, because I'm going to the same place as I want this space here. Just make sure this ID matches the one over here, which is right here, right? Okay. So again, and run. Okay. As you can see, it worked just like before. No problem. Okay. So you can do this or do the listener way. And this is the people way. Why? Because this way, I'm locked into this class, right? What if I have a separate class that want to use this? Why do you keep changing this to another class? Work out activity, user activity, somebody's activity.class. So I'm going to end up having a long list of switch case or an if and else block. If the destination is work out, then go here. Else if, else if, right? So you're really limited to that capacity. But if I'm using the listener activity, click, I don't, I don't really care. I'm not limited to however many is. Okay. Whoever it is, I'm just delegating this to whoever this object is to do his job. And over here is what this intent is happening. Because the main activity might be sending that to the work activity. Another object class might send to a different activity. So let them handle where this is supposed to go. My job is basically just to give you here's the ID. So that's why this is the prefer way to do it.