Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created December 23, 2023 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeforfun-jp/99ab6c5c50688094901554651e600dbd to your computer and use it in GitHub Desktop.
Save codeforfun-jp/99ab6c5c50688094901554651e600dbd to your computer and use it in GitHub Desktop.
How to Create Dialog Series Datepicker - Java
public class MyDialogFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
// デフォルトの日付を用意
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(requireContext(), this, year, month, day);
}
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
String msg = year + "年" + (month+1) + "月" + dayOfMonth + "日";
Toast.makeText(requireContext(), msg, Toast.LENGTH_SHORT).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment