-
-
Save codeforfun-jp/1ca5679a35fc8947d72126503f36b256 to your computer and use it in GitHub Desktop.
How to Create Dialog Series Timepicker - Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyDialogFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener{ | |
@NonNull | |
@Override | |
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { | |
// デフォルトの時刻を用意 | |
final Calendar c = Calendar.getInstance(); | |
int hour = c.get(Calendar.HOUR_OF_DAY); | |
int minute = c.get(Calendar.MINUTE); | |
return new TimePickerDialog(requireContext(), this, hour, minute, true); | |
} | |
@Override | |
public void onTimeSet(TimePicker view, int hourOfDay, int minute) { | |
String msg = hourOfDay + "時" + minute + "分"; | |
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