Android Beginner Tutorial #7 - ListViews

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on guys this is going to be another Android studio beginner tutorial in this tutorial I'm going to show you how to use list views so we'll go ahead and start your project and I'll just call it ListView now next empty activity fine and finish mine Android build your project so let's use our one of probably the most important things when developing apps like they're just so widely used that you really need to become like a master of list views and listed afters which is what I'll go over in tutorials in the future but for now we're just gonna go over let's use and like every single app every app out that uses let's use like the Facebook newsfeed Instagram newsfeed Twitter news feeds they're probably actually recycler views but it's a form of a list view you're just listing items so I'm going to show you a simple example here of how if you look - we'll start off by going into activity means and we'll go to the text tab and let's delete this hello world text we'll get rid of that go back to the design tab and let's scroll down till we find lift you right there just drag it in we're going to stick it in the top left-hand corner here and we'll give it at 90 I'll call it velvet and layout is good for mascara and mascara generally will let you you almost always want you to match parent because you want it to take up the entire layout and I know if there's some padding here so I'm going to go over to the text tab and get rid of padding or meantime I'm just going to get rid of all that that extra space that you saw you're also back in and show you so I put the padding back in you see there's extra space from the top and the sides clearly does something here with it so that's all we need to do inactivity main let's go back to main exit and we'll just stick log up here type log T hit enter and don't just sort of look you up top let's do it in the oncreate method so we'll just explain our list view I'll just call the list climb you by p-card IDs now take another login here why not just blessed mother on crepe has started successful so this list here it's only going to hold one item per I guess container of the list I mentioned earlier if you want to put more things in here like if you want to have multiple sort of columns in one row of a ListView you need a list adapter for that but we're not going to go over the stat in this tutorial this is just going to be strictly a ListView so let's create some strings add them to an array and then add the array to look through plus create some name create an array of name actually let's use an array list new ArrayList and there's going in stuff add Mitch we'll copy that in five times let's pick one more all right so now we have our names in an ArrayList now what we want to do is add the ArrayList to an adapter and then set the adapter to the ListView so what we do is we use something called an array adapter and I'm going to call it adapter new array adapter first we pass the context and then we pass a layout file this is going to determine what what the list will actually look like and we're just going to use one of the default Android one so use a simple list item one time and then for the last primer here we pass the ArrayList we just stick names and Rick and that is our adapter and then all you gonna do is set the array adapter to the list list dot set adapter and we type our array adapter here and that's all we shouldn't have to do anything else let's just run it and make sure we have no errors so that we always see that we have all the names in the list view and we can click them all or doesn't do anything we have no on click listener says the list you but we can see that everything was successfully added to look you and this tutorial still kind of short so I think I'm going to go over one more thing in it so I mentioned that this was a default layout for your lips you so I'm going to create a custom one and I'll set it to our list so let's go over to the red folder go into layout and let's create a new layout spa newly Oh read your file let's just call it without a list item layout okay so we have new layout file let's actually delete this entire linear layout same here actually I'll just change this to will be the painters text you and leave everything the same we don't need this orientation and now it's set some properties for our Texas so we can go like text size let's make it really big when we get 20 ft and change like text text color choose one of these doesn't really matter we change us to primary dark and then let's go back to now we have some properties in yellow select me in activity and let's change this we're gonna change this through our job layout list item layout and now let's run it and take a look and see where this tree looks like so now we can see our list we totally changed the colors change because we change the color the text size is Celtic change because we change the text size so that's that's just kind of a quick and easy way you can customize what the text is going to look like in your list view so as you also probably notice there's no a space between items here so I could change that by change I could change the layout height to say like 50 B P and then maybe let's do like text alignment Center and let's try and run that again and see what that looks like now you can see that the text is aligned to the center and there's a lot more space between this item as you notice to the text is aligned to the top of the list you so let's change that by setting the gravity so the set the gravity is the vertical alignment text alignment will handle the horizontal alignment so I'll plate it again and now we can see that vertically the list items are centered because of the gravity and because of the text alignment the horizontal component of the text is centered so I'll leave it here I'll let you guys play around with it that's all I'm going to go over let's use in this tutorial if it was helpful don't be a w like below follow me on Twitter for notifications when new tutorials are posted subscribe if you haven't already and thanks for watching
Info
Channel: CodingWithMitch
Views: 32,560
Rating: undefined out of 5
Keywords: android, learn android, android beginner, android beginner tutorials, android tutorial for beginners, how to make android apps, how to use listview android, how to use listviews android, how to display data in listview android, how to display data in listview, how to use listview widget android, beginner listview tutorial, android beginner listview tutorial, listview beginner tutorial
Id: SLFrwl1hFcw
Channel Id: undefined
Length: 6min 14sec (374 seconds)
Published: Mon Mar 13 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.