Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: CalendarView OnDateChangeLIstener

I've already implemented this listener in order for me to display something when a certain date is clicked, but the problem is that when i scroll the CalendarView down, it automatically displayed something but i didn't click anything, i just scrolled down to anther month in CalendarView and then there goes a, say a Toast or a Log, whichever (I guess it makes sense since the listener itself fires `onDateChange and since scrolling down the calendar also changes the date currently selected). So my question is that is there any listener for CalendarView that i might use just a alternative to ondateChange listener, inorder to avoid the situation that when i scroll down the calendarView to go to another month it automatically fired the lisntener.

Anyone who knows an alternative listner to CalendarView or anyone knows a workaround? please do share

like image 606
lemoncodes Avatar asked Sep 28 '12 13:09

lemoncodes


1 Answers

When you are scrolling the calendar onSelectedDayChange method behaves like you click on different date but that won't change current date settings. So HFDO5 was right, you just need to save current date when you create your calendar: Long date = calendar.getDate();

and check it in onSelectedDayChange.

if(callendar.getDate() != date){
date = calendar.getDate(); //new current date
//date is changed on real click...do things..

}
like image 189
Aleksa Avatar answered Sep 24 '22 06:09

Aleksa