I need to search my database basing the query on the month returned from a CalendarView. My problem is that onSelectedDayChange() event fires only when clicking, actually selecting a date not when the month is changed by swiping CalendarView. How to set up something like "onSelectedMonthChange"?
Asked
Active
Viewed 3,207 times
2 Answers
2
You can't do it with the Android CalendarView
. Look at this thread.
If you want to do it, you will have to make custom CalendarView
class which will extend
CalendarView
and implement onGestureListener
. Keep a variable curMonth
to keep account of your month. Whenever swipe left/right happen, update your month
variable accordingly.

Sachin Aggarwal
- 1,095
- 8
- 17
-
Thank you, I agree with your suggestion . How to test a fling on my PC? – alberto Sep 10 '17 at 15:19
-
@alberto Fling should work on an emulator (PC) as it's not multi-touch gesture. However, I advice mobile device to test gesture related stuff :-) – Sachin Aggarwal Sep 10 '17 at 23:51
-
hmm bad start already! public class FlingCalendaView extends CalendarView implements MyGestureListener {} show error "there is no default constructor available in 'Android.widget.CalendarView'" – alberto Sep 11 '17 at 04:04
-
Make a constructor of your own which will have an argument as context. – Sachin Aggarwal Sep 11 '17 at 06:59
-2
if you want to show next and previous months in your calendar based on some click event, then you can do it as:
Calendar c = Calendar.getInstance();
//for next month
btnNext.onClick(){
c.add(Calendar.MONTH,1);
}
//previous month
btnPrevious.onClick(){
c.add(Calendar.MONTH,-1);
}

TankRaj
- 89
- 7