Reputation: 3
I'm creating a CalendarView, but it takes the previous month instead of the current month. Help me !
<CalendarView
android:id="@+id/calendarView"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/radioGup" />
calendarView.setOnDateChangeListener { view, year, month, dayOfMonth ->
date = dayOfMonth.toString() + "-" + month.toString() + "-" +year.toString() Toast.makeText(activity,date,Toast.LENGTH_SHORT).show() adapter(date) }
says month = 1
Upvotes: 0
Views: 50
Reputation: 3394
/**
* Called upon change of the selected day.
*
* @param view The view associated with this listener.
* @param year The year that was set.
* @param month The month that was set [0-11].
* @param dayOfMonth The day of the month that was set.
*/
void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int dayOfMonth);
this will return month value from 0 to 11 ie. 0 for January 11 for December. So we have to add 1 in month value
Upvotes: 2