Android Time Picker Dialog and Example in Kotlin

Android Time Picker dialog is user interface , where user can select time. User can select time by Hour and Minutes. You can see time picker example in android default app alarm. How is working ? When a user click on any widget like Button , that time you have to set click listener. Then a user click the button Android TimePickerDialog will popup.

Android Time Picker Dialog and Example in Kotlin

 

In this tutorial, you will learn following:

  1. Overview Android Time Picker Dialog 
  2. Complete example and code of Android TimePickerDialog in kotlin

 

Let’s Build Android Android Time Picker Dialog example in kotlin:

In Android app development using kotlin language and  showing TimePickerDialog is very easy, in this example your will see how much easy. In the example the selected Time by user will show in Toast. You can show in TextView label or else where your want to use it in your app. Let’t see the steps to how to do it ..(Note : there is many way to do it)

 

Step 1. Create a new project “Build Your First Android App in Kotlin
Step 2. Add following code in “activity_main.xml” layout file

Where button have method to perform a onClick action.

Step 3. Open the “MainActivity.kt” and add following code

On clicking button – Creates a new time picker dialog for the current time using the parent context’s default time picker dialog theme. Context is requires the application context.

  • var hour : It shows the the current hour that’s visible when the dialog pops up
  • var minute : It shows the the current minute that’s visible when the dialog pops up

 

Step 4. NowRun the application, in emulator or On you android device
Output screenshot Android Time Picker Dialog :

 

Android Time Picker Dialog and Example in Kotlin output

 

Download source code Android TimePickerDialog in kotlin

https://github.com/eyehunt/AndroidTimePicker

 

Note : This example (Project) is developed in Android Studio 3.1.3 . Tested on Android 9 ( Android-P), compile SDK version API 27: Android 8.0 (Oreo)

MinSdkVersion=”15″

TargetSdkVersion=”27″

Coding in Kotlin


One thought on “Android Time Picker Dialog and Example in Kotlin

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.