Advertisement
sigrundish

Untitled

Apr 26th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. package com.example.sigrundish.actio;
  2.  
  3. import android.app.Dialog;
  4. import android.app.DialogFragment;
  5. import android.app.TimePickerDialog;
  6. import android.icu.util.Calendar;
  7. import android.os.Build;
  8. import android.os.Bundle;
  9. import android.support.annotation.RequiresApi;
  10. import android.text.format.DateFormat;
  11. import android.widget.TimePicker;
  12.  
  13. public class TimePickerFragment extends DialogFragment
  14.         implements TimePickerDialog.OnTimeSetListener {
  15.  
  16.     @RequiresApi(api = Build.VERSION_CODES.N)
  17.     @Override
  18.     public Dialog onCreateDialog(Bundle savedInstanceState) {
  19.         // Use the current time as the default values for the picker
  20.         final Calendar c = Calendar.getInstance();
  21.         int hour = c.get(Calendar.HOUR_OF_DAY);
  22.         int minute = c.get(Calendar.MINUTE);
  23.  
  24.         // Create a new instance of TimePickerDialog and return it
  25.         return new TimePickerDialog(getActivity(), this, hour, minute,
  26.                 DateFormat.is24HourFormat(getActivity()));
  27.     }
  28.  
  29.     public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
  30.         // Do something with the time chosen by the user
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement