Most visited

Recently visited

Added in API level 1

DatePickerDialog

public class DatePickerDialog
extends AlertDialog implements DialogInterface.OnClickListener, DatePicker.OnDateChangedListener

java.lang.Object
   ↳ android.app.Dialog
     ↳ android.app.AlertDialog
       ↳ android.app.DatePickerDialog


一个包含 DatePicker简单对话框。

请参阅 Pickers指南。

Summary

Nested classes

interface DatePickerDialog.OnDateSetListener

监听者用来指示用户完成选择日期。

Inherited constants

From class android.app.AlertDialog
From interface android.content.DialogInterface

Public constructors

DatePickerDialog(Context context)

使用父上下文的默认日期选择器对话框主题为当前日期创建新的日期选择器对话框。

DatePickerDialog(Context context, int themeResId)

为当前日期创建一个新的日期选择器对话框。

DatePickerDialog(Context context, DatePickerDialog.OnDateSetListener listener, int year, int month, int dayOfMonth)

使用父上下文的默认日期选择器对话框主题为指定日期创建新的日期选择器对话框。

DatePickerDialog(Context context, int themeResId, DatePickerDialog.OnDateSetListener listener, int year, int monthOfYear, int dayOfMonth)

为指定的日期创建一个新的日期选择器对话框。

Public methods

DatePicker getDatePicker()

返回此对话框中包含的 DatePicker

void onClick(DialogInterface dialog, int which)

当单击对话框中的按钮时,将调用此方法。

void onDateChanged(DatePicker view, int year, int month, int dayOfMonth)

根据日期变化调用。

void onRestoreInstanceState(Bundle savedInstanceState)

从先前保存的包中恢复对话框的状态。

Bundle onSaveInstanceState()

将对话框的状态保存到一个包中。

void setOnDateSetListener(DatePickerDialog.OnDateSetListener listener)

设置侦听器在用户设置日期时调用。

void updateDate(int year, int month, int dayOfMonth)

设置当前日期。

Inherited methods

From class android.app.AlertDialog
From class android.app.Dialog
From class java.lang.Object
From interface android.content.DialogInterface
From interface android.view.Window.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.View.OnCreateContextMenuListener
From interface android.content.DialogInterface.OnClickListener
From interface android.widget.DatePicker.OnDateChangedListener

Public constructors

DatePickerDialog

Added in API level 24
DatePickerDialog (Context context)

使用父上下文的默认日期选择器对话框主题为当前日期创建新的日期选择器对话框。

Parameters
context Context: the parent context

DatePickerDialog

Added in API level 24
DatePickerDialog (Context context, 
                int themeResId)

为当前日期创建一个新的日期选择器对话框。

Parameters
context Context: the parent context
themeResId int: the resource ID of the theme against which to inflate this dialog, or 0 to use the parent context's default alert dialog theme

DatePickerDialog

Added in API level 1
DatePickerDialog (Context context, 
                DatePickerDialog.OnDateSetListener listener, 
                int year, 
                int month, 
                int dayOfMonth)

使用父上下文的默认日期选择器对话框主题为指定日期创建新的日期选择器对话框。

Parameters
context Context: the parent context
listener DatePickerDialog.OnDateSetListener: the listener to call when the user sets the date
year int: the initially selected year
month int: the initially selected month (0-11 for compatibility with MONTH)
dayOfMonth int: the initially selected day of month (1-31, depending on month)

DatePickerDialog

Added in API level 1
DatePickerDialog (Context context, 
                int themeResId, 
                DatePickerDialog.OnDateSetListener listener, 
                int year, 
                int monthOfYear, 
                int dayOfMonth)

为指定的日期创建一个新的日期选择器对话框。

Parameters
context Context: the parent context
themeResId int: the resource ID of the theme against which to inflate this dialog, or 0 to use the parent context's default alert dialog theme
listener DatePickerDialog.OnDateSetListener: the listener to call when the user sets the date
year int: the initially selected year
monthOfYear int: the initially selected month of the year (0-11 for compatibility with MONTH)
dayOfMonth int: the initially selected day of month (1-31, depending on month)

Public methods

getDatePicker

Added in API level 11
DatePicker getDatePicker ()

返回此对话框中包含的 DatePicker

Returns
DatePicker the date picker

onClick

Added in API level 1
void onClick (DialogInterface dialog, 
                int which)

当单击对话框中的按钮时,将调用此方法。

Parameters
dialog DialogInterface: The dialog that received the click.
which int: The button that was clicked (e.g. BUTTON1) or the position of the item clicked.

onDateChanged

Added in API level 1
void onDateChanged (DatePicker view, 
                int year, 
                int month, 
                int dayOfMonth)

根据日期变化调用。

Parameters
view DatePicker: The view associated with this listener.
year int: The year that was set.
month int: The month that was set (0-11) for compatibility with Calendar.
dayOfMonth int: The day of the month that was set.

onRestoreInstanceState

Added in API level 1
void onRestoreInstanceState (Bundle savedInstanceState)

从先前保存的包中恢复对话框的状态。 默认实现恢复默认实现onSaveInstanceState()保存的对话框视图层次结构的onSaveInstanceState() ,因此,除非您想自己完成所有状态的恢复,否则一定要在覆盖时调用超级对象。

Parameters
savedInstanceState Bundle: The state of the dialog previously saved by onSaveInstanceState().

onSaveInstanceState

Added in API level 1
Bundle onSaveInstanceState ()

将对话框的状态保存到一个包中。 默认的实现保存了它的视图层次结构的状态,所以如果你重写这个来保存更多的状态,你可能想要调用super。

Returns
Bundle A bundle with the state of the dialog.

setOnDateSetListener

Added in API level 24
void setOnDateSetListener (DatePickerDialog.OnDateSetListener listener)

设置侦听器在用户设置日期时调用。

Parameters
listener DatePickerDialog.OnDateSetListener: the listener to call when the user sets the date

updateDate

Added in API level 1
void updateDate (int year, 
                int month, 
                int dayOfMonth)

设置当前日期。

Parameters
year int: the year
month int: the month (0-11 for compatibility with MONTH)
dayOfMonth int: the day of month (1-31, depending on month)

Hooray!