Is there a way to set the date/time shown on a date picker or time picker which the user can then edit? I have looked on the android developer console and found nothing but i was wondering if there was still a way?
Asked
Active
Viewed 394 times
0
-
Take a look at [this](https://github.com/code-troopers/android-betterpickers) coming from [here](http://stackoverflow.com/a/20223949/316555) – isaias-b Feb 19 '16 at 15:37
-
yes. Store the selected data/time in a `Calender` instance and then set that to the date/time picker next time the user opens it. – Elvis Chweya Feb 19 '16 at 15:38
2 Answers
1
Sure, TimePicker
and DatePicker
classes have the appropriate setters to set the desired time/date after you have instantiated them.
example:
final Calendar c = Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
timePicker1 = (TimePicker) findViewById(R.id.timePicker1); //supposed you have defined the "timePicker1" id in your layout xml
timePicker1.setCurrentHour(hour);
timePicker1.setCurrentMinute(minute);

pleft
- 7,567
- 2
- 21
- 45
-
What about for datepicker? i got the timepicker to work but not for datepicker, there is not function for setting the date – Elliot Archer Feb 24 '16 at 12:31
-
@ElliotArcher Read the DatePicker api for the init method: http://developer.android.com/reference/android/widget/DatePicker.html – pleft Feb 24 '16 at 14:44