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?
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.