选择对话框 android
Android Date Time picker are used a lot in android apps. In this tutorial we’ll demonstrate the use of a Date Picker and Timer Picker Dialog in our android application. These components are used to select date and time in a customised user interface. We will use DatePickerDialog
and TimePickerDialog
classes with Calendar
class in our android application code to achieve this.
Android日期时间选择器在android应用程序中经常使用。 在本教程中,我们将演示在Android应用程序中如何使用日期选择器和计时器选择器对话框。 这些组件用于在自定义的用户界面中选择日期和时间。 我们将在Android应用程序代码中将DatePickerDialog
和TimePickerDialog
类与Calendar
类一起使用,以实现此目的。
Android DatePickerDialog和TimePickerDialog (Android DatePickerDialog and TimePickerDialog)
Though a Date Picker and Time Picker can be used as independent widgets but they occupy more space on the screen. Hence using them inside a Dialog is a better choice. Fortunately android provides use with its own DatePickerDialog and TimePickerDialog classes.
尽管可以将Date Picker和Time Picker用作独立的小部件,但它们在屏幕上占据了更多空间。 因此,在对话框中使用它们是更好的选择。 幸运的是,android提供了自己的DatePickerDialog和TimePickerDialog类。
DatePickerDialog and TimePickerDialog classes have onDateSetListener()
and onTimeSetListener()
callback methods respectively. These callback methods are invoked when the user is done with filling the date and time respectively.
DatePickerDialog和TimePickerDialog类分别具有onDateSetListener()
和onTimeSetListener()
回调方法。 当用户分别填写日期和时间后,将调用这些回调方法。
The DatePickerDialog class consists of a 5 argument constructor with the parameters listed below.
DatePickerDialog类由5个参数的构造函数以及下面列出的参数组成。
- Context: It requires the application context 上下文 :它需要应用程序上下文
- CallBack Function:
onDateSet()
is invoked when the user sets the date with the following paramete