How to create a Date & Time Picker Dialog in Android Studio (Kotlin 2020)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right so hello and welcome to another Android studio tutorial in this video we'll be showing you how to create this date picker and as well as the date picker wheels gonna create a time picker so you can just use both of those it's actually very simple to implement and I wish I knew this a long time ago but let's get started immediately by going to our layout and tapping on activity main.xml here you can just copy and paste applied it but I'll just explain very briefly I created a relative layout and I added a button and this button I just named button underscore time picker then I added the text view which went directly under the button and I gave it an ID of TV on the score text time and that's essentially it I just gave it a sample text to show but the faster you want to do on your main activity file is extend date picker dialog on state set listener and the same thing for time picker and implement those methods by right-clicking on class main activity and then immediately after that we are going to create a whole lot of variables which is gonna be for the day month year hour and finally minute and immediately after that we are going to copy and paste our initial set of variables and we are going to change the names on all of them I just named them saved a same saves month saved year and so on and essentially these are going to be used to post the updated information to the textview and as you can see there are used command shift + 8 as a special shortcut and after that we're just gonna create a method called pick date and a private function which is gonna be right under there and it's gonna be called get date/time calendar this is gonna get an instance of our calendar and then immediately sign the values to our variables that we just created earlier and this is just to make sure that the information on our calendar is up to date and next we will implement our pick date function and we are going to write button underscore time picker set an onclicklistener for that and we are going to type they pick a dialogue with the context of this this and then we're going to write here month day and put a dot show on it and that's gonna open our date picker dialog and here we will implement the function or the codes that is gonna be used for our date picker dialogue so we're going to write safe day equals safe month SafeMart equals month and safety R equals year so it will assign those values to our saved years and months we're gonna get get time calendar to update the time on the calendar we're gonna do the same thing for the time picker dialog as you can see down there is almost essentially exactly the same as creating a date picker dialog but I said that we just need to update the TV dot text time text you and just add all the values that we picked because these over overridden functions update the values for us and it's very simple and yeah mostly I would just say copy what you see here since it's very self-explanatory but otherwise that's all there is to creating a date picker or a time picker if you have any other questions regarding this just leave them in the comment section below otherwise go on Stack Overflow or check on Google first but to do exactly what you see on the screen here that's all you need but thanks for watching and I hope to soon another tutorial
Info
Channel: Indently
Views: 29,352
Rating: undefined out of 5
Keywords: android studio, code, coding, program, programming, tutorials, android, studio, java, kotlin, python, c#, how to, app, applications, developer, developement, learn coding, learn programming, free
Id: GmmyCOpIutA
Channel Id: undefined
Length: 3min 16sec (196 seconds)
Published: Sun May 10 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.