android development tutorial time dialog box core code

  • 2020-06-01 10:58:17
  • OfStack


new TimePickerDialog(MainActivity.this, new TimePickerDialog.OnTimeSetListener() {

 @Override
 public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                c.setTimeInMillis(System.currentTimeMillis());
                c.set(Calendar.HOUR_OF_DAY, hourOfDay);// When setting the pop-up dialog box 
                c.set(Calendar.MINUTE, minute); // Set the points of the pop-up dialog box 
                c.set(Calendar.SECOND, 0); //  Set to  0
                c.set(Calendar.MILLISECOND, 0); //  Set to  0
                }
  }
  }, minute, minute, true).show();

The TimePickerDialog method has five parameters. The first parameter (MainActivity.this) is the activity pointer where the pop-up time dialog box is located. The second parameter we end up with; The third parameter (hour) and the fourth parameter (minute) are the initial display hours and minutes of the time dialog box that pops up. The fifth parameter is the display parameter set at 24 hours, and true represents the time displayed at 24 hours.


Related articles: