Reputation: 5954
I have implemented CalendarView in my Android App. I have a strange issue on selection of the date. The month is showing April 2015 in the top but the toast is showing 1/3/2015? If I Scroll May 2015 the toast shows 1/4/2015. The month is always a previous month.
I am doing something like this:
calendar =(CalendarView) findViewById(R.id.calendarforstart);
calendar.setShowWeekNumber(false);
calendar.setFirstDayOfWeek(2);
calendar.setOnDateChangeListener(new OnDateChangeListener()
{
@Override
public void onSelectedDayChange(CalendarView view, int year, int month, int day)
{
Toast.makeText(getApplicationContext(), day + "/" + month + "/" + year, Toast.LENGTH_LONG).show();
}
});
Please check the snapshot:
Did you notice in the top it shows April 2015 but the below the toast shows 1/3/2015.. Why is this happening?
Can anybody help me fix this?
Thanks!
Upvotes: 0
Views: 1771
Reputation: 12358
Month start with 0. so jan-dec
is like 0-11
you need to change it to month+1
Toast.makeText(getApplicationContext(), day + "/" + (month+1) + "/" + year, Toast.LENGTH_LONG).show();
Upvotes: 5