본문 바로가기
#모바일 [Mobile]/Android

[Android] Date Picker Dialog

by cy_mos 2019. 7. 22.
반응형
[Android] Date Picker Dialog

[Android] Date Picker Dialog

 


📄 Date Picker Dialog Listener Source Code

// TODO: - DatePickerDialog Listener
	private DatePickerDialog.OnDateSetListener onDatePickerListener = new DatePickerDialog.OnDateSetListener() {
		@Override
		public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {

			monthOfYear++;

			final String day = dayOfMonth / 10 == 0 ? "0" + dayOfMonth : Integer.toString(dayOfMonth);
			final String month = monthOfYear / 10 == 0 ? "0" + monthOfYear : Integer.toString(monthOfYear);

			Toast.makeText(view.getContext(), String.format("%d-%d-%d", year, monthOfYear, dayOfMonth), Toast.LENGTH_SHORT).show();
		}
	};

📄 Date Picker Dialog Source Code

final Calendar mCurrentTime = Calendar.getInstance();
final DatePickerDialog mDatePickerDialog = new DatePickerDialog(this,
			this.onDatePickerListener,
			mCurrentTime.get(Calendar.YEAR),
			mCurrentTime.get(Calendar.MONTH),
			mCurrentTime.get(Calendar.DAY_OF_MONTH)
);

mDatePickerDialog.show();

🚀 REFERENCE

 

DatePickerDialog  |  Android Developers

From class android.app.AlertDialog Button getButton(int whichButton) Gets one of the buttons used in the dialog. ListView getListView() Gets the list view used in the dialog. void onCreate(Bundle savedInstanceState) Similar to Activity#onCreate, you should

developer.android.com

 

반응형

댓글