The data type of God is the base class now let’s call it the adapter this new array adapter now I need to also make this course.
The generic based on that and then the constructor that’s control one and I’m going to import.
The array adapter and correct the spelling on string now here if I were control space it gives me the list of possible constructors that I can use.
We see there’s a bunch of different constructors here I’m going to use one that is going to work with generating these layouts for me so the idea is that this area adapter is going to take this array of strings and it’s gonna build me the different layouts that I’m going to need for my ListView I need some context to an activity and then I’m going.
To give it the appropriate layout to work with so that’s gonna be our layout dot and here are the layouts that are defined and here’s the item that we just defined before and then I need to.
Give it the list of elements so my items let’s just break this out and add some comments here to make it clear what’s going on so these are the items to be displayed here we.
Have the layout to use ie create it’s going to create a bunch of these and then this is just some context so now I need to set up the ListView to use this so I need to.
Get my ListView it’s gonna be our dot ID dot and hmm where’s my list view.
It’s not showing up well I think I haven’t saved my file let’s go back over here the name is set control us to save come back in here that should.
Have Auto regenerated it and there we go a ListView made so I get my ListView then.
I say list dot said adapter and then I pass in the adapter which I just happened to have call adapter so now when we run populate ListView.
Is going to be called we create the list of elements we want to display we set up my adapter and then I pass it into the ListView let’s run that see what happens and then we have it here’s my list of elements.
You see I can click on them and it shows me that something happened although nothing.
Actually cookers so I’ve got my elements how can I actually register for clicks let’s maybe put up a toast message whenever you click.
On it and have it say purple or red so coming back into here I don’t need to set up my on click so let’s create a new function register click call back I can move it down to the bottom because I want it to be below it doesn’t have to I don’t want to duplicate that’s.
Alright it doesn’t have to be the ordering but I like to have my functions ordered in a meaningful manner so what am I going to do in this well I need to first off set up an.
Onclicklistener with my list view and then populate that list or can figure the listener for whatever it is I want.
To have happen so on my list which I happen to just gonna copy.
And paste this code get the list on the list I’m going to say I’m going to set the onclicklistener set on click now we have a few things here there’s a on you.
Move a cursor there’s an on click list and there’s also an on item click listener so you have a click listener it’s if you click on the ListView itself the.