ListView in Android Studio using Kotlin | Android Knowledge

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign welcome back to my channel in this video we will create a simple list view as this series will cover all the important topics from beginner to Advanced in kotlin so initial topics might sound very easy to you but I believe as a beginner you should be very confident enough about the basics then only you will be able to understand intermediate and advanced topics okay also I have observed that my Java videos has more views as compared to kotlin so it seems like people have not fully accepted codeine yet but trust me the future of Android is in codeine so I request you to switch to 14 as early as possible alright let's come back to our today's video as it's a beginner video hence we will be creating a simple list view but we do have something called as custom list view which I have already created a video on it you can click on the I button to watch but that's a little intermediate version of it okay so for now let's stick to the basics so choose empty views activity then click ok name the project as listview and click finish so first let's do the prerequisites go to collects.xml press Ctrl D to duplicate the line then name the color as blue and hex code AS 1a90 F1 and then go to strings.xml I'll change the app name to-do list and then go to themes.xml change the parent from no action bar to dark action bar now we need to add three parameters let me first uncomment this so the first item name is color primary and set the color as blue then Control Plus t and second item name is color primary variant then third item name is status bar color all three of them the color will be blue perfect now we are done with the prerequisite let's move on to activity main.xml so to make it easy for you I have divided list view in five steps so the step number one is to create a list view an activity me so let me quickly create it and then I'll explain you [Music] and it's done so we have given an ideas list view then height width as match parent then I wanted a little gap between the action bar and list view hence I have kept the margin top as 8dp then lastly all the four corner the constraints and then now let's go to main activity as we are done with the step number one so now let's move to step number two initialize the list view variable which we just created then we need to create an array list and in that arraylist we will store all the list items so in kotlin you just need to write array of and inside that mention all the items so let me quickly do that and then I have added five items in it okay now step number three is all about adapter if we were creating a custom list view in that case we would have created a new adapter class and customize it accordingly got it but as we are creating a simple list view hence we will be using a predefined adapter okay and as we are using arraylist so we will go for arrayadapter first let me write the code and then I'll explain you so we have created an array adapter and stored it in the variable called as list adapter got it now let's understand the syntax of arrayadapter so over here we have three part first represents the current activity which we refer to as this means our main activity then second represents the layout so we will be using a predefined layout of list view which is provided by the ID itself that is simple list item 1. and then third should contain the error list so we have created an arraylist named as list item right so we will mention it over here okay then in the same step we will set the adapter on the list view if you remember in Java we used to write a set adapter method but in kotlin you just have to write adapter and we are done with this step number three now our next step is Step number four so our list view is created but we need to make sure that all the items in the list we should be clickable right so to do that we need to set on item click listener on the list View now to make the code readable we will rename the parameters so adapter will become as parent then is position and LS ID now what we will do is when the user clicks on the list item then a toast will be shown as you have clicked on whatever the item name is so how we will do it logically we have few parameters over here right so out of which we will require two of them the first is parent means the entire list view or adapter View and second is position means as you are aware how array works right they all are have their index positions like 0 1 2 correct so we will store all the positions inside a variable so let me quickly write the code and then I'll explain you see we have stored the item position using the get item at position method in this selected item variable in a form of a string then I have wrote a toast that you have clicked on the selected item now dollar is used to refer the particular position of the item and with that said we are done with the coding part now the last step that is a step number five run the app see all the items are in the list format so when I click on a read a book then a toast appears you have clicked on read a book perfect so yeah that's it also make sure to save the playlist because I'll be uploading new videos such as recyclerview fragments mvpm core routines Credit in Firebase and many more not only that but by the end of the playlist we'll be creating projects such as news app with app to-do list and many more so make sure that you follow the playlist so yeah that is it for the video if you are new to this Channel please consider subscribing to my channel and I'll see you in the next video [Music] foreign
Info
Channel: Android Knowledge
Views: 3,570
Rating: undefined out of 5
Keywords: listview android studio, android studio, simple listview android studio, listview android, create a simple listview android studio, listview in android, android tutorial, custom listview android tutorial, custom listview in fragment android studio, custom listview in android kotlin, custom listview android java, android listview tutorial, android, beautiful listview android, custom listview in android, android custom listview, custom listview in android - stack overflow, kotlin
Id: BntLlH4eSYA
Channel Id: undefined
Length: 9min 3sec (543 seconds)
Published: Thu Jun 08 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.