Android Time Picker Dialog Tutorial with Example – How to use TimePickerDialog

By | May 29, 2019
TimePicker Dialog in Android Tutorial Example

What is TimePickerDialog ?

TimePicker Dialog is a selected of time day,24 hours and AM/PM.  The time consists of hours, minutes and clock format. Android provides this functionality through TimePicker class.

TimePicker to set time is hour and minutes. it can not selected or set time in seconds.

Methods of TimePickerDialog

setCurrentHour(Integer currentHour) : In this method used to set current hour.it is one parameter to set hour.

setCurrentMinute(Integer currentMinute) : In this method used to set current Minute.it is required one parameter set to minute.

is24HourView() : In this method to returns true if this is in 24 hour view else false.

setIs24HourView(Boolean is24HourView) : In this method used to Set 24 hour or AM/PM mode.

setOnTimeChangedListener(TimePicker.OnTimeChangedListener onTimeChangedListener) : In this method use it can listener when you can set the time on timepicker dialog this method is called.

How to Create TimePickerDialog with Example ?

Create activity_main.xml File following this code.

Create MainActivity.java File Follow this code.

In this Exmple is Create XML of One TextView to display date when you can selected timepicker dialog.And Then One Button when you can click to display timepicker dialog.Now i have implement id of button and textview and i have create calendar class object.calendar is used to get the current date time.and then create two integer variable is hour and minute. in this variable store to get calendar current hour and minute date.now i have implement button click listener and create TimePickerDialog object.

when you can create TimePickerDialog class object to give two parameter first is context means which activity to diaplay dialog.and second is dialog listener of onTimeSetListener.in this method use of when you can select hour and minute on the timepicker dialog and then click OK to display time you want to selected.