individuals are making remindersfunctionwhen I used the timepickerdialog.dialog Box, consulted a lot ofTechnologyinformation, but feel a lot of things are not very detailed, and many places, there are imperfect places, such as the Pop-up dialog box to get notsystemthe currentTime, but a phenomenon of other time, makes people very depressed. So after a few degrees of research, I decided to put my personalSpacepart of the understanding to discuss with you, if there is something wrong, please understand, will be improved.
gossip does not say much, directly into the subject:
First, we want to declare a calendar object in the program and instantiate it to get the calendar instance, which is used later.
private Calendar C = calendar.getinstance ();
after instantiation, the calendar object can be manipulated, such as the C.get method can get related variables in the Calendar object (such as year, month, day, hour, minute, second, etc.), the values of these variables in the instantiation of "C = calendar.getinstance ();" is set to the system default time, and the C.set method can be used to set the related variables of the calendar object.
Another important method for calendar objects is Settimeinmillis, which has only one parameter, that is, the number of milliseconds from 0 o'clock January 1, 1970, which, if you want to set the current system time, will set the variables in the calendar object according to the number of milliseconds that you have passed in. , use the following method: "C.settimeinmillis (System.currenttimemillis ());"
The following goes into the lead, the development of the Time dialog box . Give some implementation code, specific details, their own painstaking research
e1 = (EditText) Findviewbyid (r.id.c1_time); E1.setonclicklistener (new Onclicklistener () {@Override public vo ID OnClick (View v) {C.settimeinmillis (System.currenttimemillis ()); int mhour = C.get (Calendar.hour_of_day); int mminute = C.get (Calendar.minute); New Timepickerdialog (Classtimeset.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); C.set (Calendar.minute, MINUTE); C.set (Calendar.second, 0); Set to 0 C.set (Calendar.millisecond, 0); Set to 0}}, Mhour, Mminute, True). Show (); }});
Determine if the hours and minutes of the time are less than 10 of the case string strhourofday = Hourofday < 10? "0" + hourofday: "" + hourofday;
String Strminute = Minute < 10? "0" + minute: "" + minute;
The Timepickerdialog method has five parameters, the first parameter (menuview.this) is the activity pointer where the popup time dialog box is located, and the second argument we finally say; the third argument (hour) and the fourth argument (minute) For the hours and minutes of the initial display of the popup time dialog, these two variables are initialized in blue code, and the fifth parameter is set 24 o'clock to display the parameter, and true to show time as 24 o'clock.