I have a Calendarview and an Edittext. I wish to take the date entered in the edittext in the format DD/MM/YYYY and set it on the Calendarview. The view should update the current date bubble to the set date.
I have already tried: How to set focus on a specific date in CalendarView knowing date is "dd/mm/yyyy"
This is my current code:
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, 2019);
calendar.set(Calendar.MONTH, Calendar.JUNE);
calendar.set(Calendar.DAY_OF_MONTH, 20);
long milliTime = calendar.getTimeInMillis();
CalendarView calendarView = findViewById(R.id.calendar);
calendarView.setFocusedMonthDateColor(Color.BLUE); //apparently this is deprecated so won't work. Not working without it either.
calendarView.setDate (milliTime); //this is supposed to change the date but isn't
Thanks in advance!
I have read your question and i have try to solve this problem. pass date(time in milliseconds) in long type value to set date in calendar view like this calendar_view.setDate(milliTime);
try this code to achieve your goal .
Code
calendar_view = findViewById(R.id.calendar_view);
//replace date variable static value to your edit text
value
String date = "25/06/2019";
String parts[] = date.split("/");
int day = Integer.parseInt(parts[0]);
int month = Integer.parseInt(parts[1]);
int year = Integer.parseInt(parts[2]);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DAY_OF_MONTH, day);
long milliTime = calendar.getTimeInMillis();
calendar_view.setDate(milliTime);
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.