Basic Listview Demo: Android Programming

And I see nope come opposite you see here we have a ListView so I can drag that in and place it here and it puts in a bunch of sort of just duh ghost items so they can show what its gonna look like on my screen let’s bump that up so it feels more of the screen so let’s.

Give this a name let’s call this list view that’s what I mean now what I’m gonna want to do is I’m gonna want to be able to put my data inside of that so how am I.

Gonna do that well I’m gonna have to do those that through my java code and let’s switch over and have a look at whether we’re gonna go with that so the basic idea is and I’ll get rid of this on create options menu don’t need the basic idea is that I’m gonna have code that I can have an array array of options this will be my text that I want to put in.

The USU and I’m gonna have to run that through what’s called an array adapter and then array adapter can then populate my list view so that’s sort of the process I’m going to use now this ListView actually is more than just the ListView as we seen it we have to describe what we want in that list view the list you just shows a bunch of things a bunch of layouts one after.

The next and we have to do that so my ListView is going to be a set of a.

Whole bunch of these sort of we’ll call it of views and so I’ve got to go and create those views and so I’m going to.

Name this to be let’s just give it a funny name from the what’s called items and it’s actually gonna be XML so I’m gonna go and create that now.

So under layout I’m going to right-click and then create a new Android XML file and then here I can specify what route I want now normally we might say well I’d like a you know relative layout or something there’s one here called a text box and I’m going to use the text.

Box or textview pardon me to to be my base because at the moment I’m just gonna put a single were a single string in each entity.

On my list box so I’m gonna give it a name and I guess item dot XML it comes up it looks like it’s gonna be an activity but it’s not if we go to the exo XML we can see here that it is just a single textview that’s good that’s what I want for the moment now what I’m gonna have to do is I’m going to have to populate this throughout my Java code so in here.

In my own create now let’s create a function here called populate ListView so what am I going to have to do inside populate ListView.

Well I’m going to want to be able to you first get the ListView to work with and then I’m going to want to.

Be able to put the items in it so we’re going to but what’s create I create a list list of items we’re then going to build the adapter and then finally I’m going to configure.
The ListView so let’s go over.

The list of strings that we want to display so I wanted an array of strings and it’s call it my items and then I can just create a list here so let’s come up with colors so blue green purple red so those are the ones that I want to.

There now my adapter is going to actually convert these items into the appropriate elements the appropriate views that I want to work with so I’m going to create an array list and hit array adapter pardon me and it’s gonna work on strings which is.