Android Studio - TimePickerDialog Tutorial (2018)

Published: 30 August 2018
on channel: Programming Hustle
5,921
62

Welcome to TimePickerDialog Android Tutorial. In this tutorial we are going to create TimePickerDialog and choose time for our TextView.

TimePickerDialog is a class that extends AlertDialog class. TimePicker let's user choose time, in this case when we choose time and click on "Ok" our TextView updates.

First step is to create layout, for that we just need one Button(for opening TimePickerDialog) and one TextView(for diplaying choosen time).

Now when we are done with layout we can safely jump into coding. Next step is to of course declare and initialize Button and TextView. Now when we finish that we need to set onClickListener for our Button.

When user clicks on that button we want TimePicker to appear. Now let's create TimePickerDialog object. First parameter is context, second one is TimePickerDialog.onTimeSetListener. We want to Override method of onTimeSetListener that's called onTimeSet because that is a method that gives us choosen time in Time Picker. Here we update our TextView.

Third parameter is hour, 4th is minute and last one is displayed format for Time Picker - is it 24 hour format or 12h hour format.

Last thing we ought to do is to call show() function of our TimePickerDialog class.
--------------------------------------------------
For more tutorials subscribe to Programming Hustle channel


On this page of the site you can watch the video online Android Studio - TimePickerDialog Tutorial (2018) with a duration of hours minute second in good quality, which was uploaded by the user Programming Hustle 30 August 2018, share the link with friends and acquaintances, this video has already been watched 5,921 times on youtube and it was liked by 62 viewers. Enjoy your viewing!