안드로이드 DataPicker Dialog 사용해서 날짜 입력받기


Android/코드창고 2012.01.30 14:56



Public Constructors

public DatePickerDialog (Context context, DatePickerDialog.OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth)

Since: API Level 1

Parameters
contextThe context the dialog is to run in.
callBackHow the parent is notified that the date is set.
yearThe initial year of the dialog.
monthOfYearThe initial month of the dialog.
dayOfMonthThe initial day of the dialog.

public DatePickerDialog (Context context, int theme, DatePickerDialog.OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth)

Since: API Level 1

Parameters
contextThe context the dialog is to run in.
themethe theme to apply to this dialog
callBackHow the parent is notified that the date is set.
yearThe initial year of the dialog.
monthOfYearThe initial month of the dialog.
dayOfMonthThe initial day of the dialog.

Public Methods

public DatePicker getDatePicker ()

Since: API Level 11

Gets the DatePicker contained in this dialog.

Returns
  • The calendar view.

public void onClick (DialogInterface dialog, int which)

Since: API Level 1

This method will be invoked when a button in the dialog is clicked.

Parameters
dialogThe dialog that received the click.
whichThe button that was clicked (e.g. BUTTON1) or the position of the item clicked.

public void onDateChanged (DatePicker view, int year, int month, int day)

Since: API Level 1

Called upon a date change.

Parameters
viewThe view associated with this listener.
yearThe year that was set.
monthThe month that was set (0-11) for compatibility with Calendar.
dayThe day of the month that was set.

public void onRestoreInstanceState (Bundle savedInstanceState)

Since: API Level 1

Restore the state of the dialog from a previously saved bundle. The default implementation restores the state of the dialog's view hierarchy that was saved in the default implementation of onSaveInstanceState(), so be sure to call through to super when overriding unless you want to do all restoring of state yourself.

Parameters
savedInstanceStateThe state of the dialog previously saved by onSaveInstanceState().

public Bundle onSaveInstanceState ()

Since: API Level 1

Saves the state of the dialog into a bundle. The default implementation saves the state of its view hierarchy, so you'll likely want to call through to super if you override this to save additional state.

Returns
  • A bundle with the state of the dialog.

public void updateDate (int year, int monthOfYear, int dayOfMonth)

Since: API Level 1

Sets the current date.

Parameters
yearThe date year.
monthOfYearThe date month.
dayOfMonthThe date day of month.


위 개발문서 참고해서 DataPicker Dialog 사용을 해주시길 바랍니다. 
DataPicker은 날짜를 선택받는 안드로이드에서 제공해주는 API 입니다. 
아마 많은 어플에서 보셨을텐데요. 간단하게 예를 사용하면,

 Calendar c = Calendar.getInstance();
        int cyear = Integer.parseInt(selected_year);
        int cmonth = Integer.parseInt(selected_month)-1;
        int cday = Integer.parseInt(selected_day);
// Calendar 을 통해 현재 날짜를 받아옴,  

        DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener()
        {
            public void onDateSet(DatePicker view, int year, int monthOfYear,
                int dayOfMonth)
            {
///실제적으로 선택된 날짜를 Set하는 등의 명령

             }
};

로 사용이 가능합니다.
(기본적인 예제이니 응용해서 사용하셔요)

 
 
저작자 표시 비영리 변경 금지
신고

WRITTEN BY
ShakeJ

0 ,