fun calShow(ctx: Context){
val simpleDateFormatRangeStart = SimpleDateFormat("yyyy-MM-dd", Locale.ROOT)
simpleDateFormatRangeStart.format(Date())
val simpleDateFormatRangeEnd = SimpleDateFormat("yyyy-MM-dd", Locale.ROOT)
simpleDateFormatRangeEnd.format(Date())
val calendarSheet = CalendarSheet().build(ctx) { // Build and show
title("calendarTitle") // Set the title of the sheet
maxRange(3650)
calendarMode(CalendarMode.MONTH)
selectionMode(SelectionMode.RANGE)
setSelectedDateRange(simpleDateFormatRangeStart.calendar, simpleDateFormatRangeEnd.calendar)
displayButtons(true)
onPositive { dateStart, dateEnd ->
Log.d("***", dateStart.toString())
Log.d("***", dateEnd.toString())
}
}
calendarSheet.show()
}
In this case if quick tap on button (button2 in my activity) for several times i got crash with this error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.test.calendartest, PID: 22379
java.lang.IllegalStateException: Fragment CalendarSheet{...} (...) not attached to a context.
at androidx.fragment.app.Fragment.requireContext(Fragment.java:900)
at com.maxkeppeler.sheets.calendar.CalendarSheet$setupDayDesign$2.invoke(CalendarSheet.kt:582)
at com.maxkeppeler.sheets.calendar.CalendarSheet$setupDayDesign$2.invoke(CalendarSheet.kt:65)
at com.maxkeppeler.sheets.core.utils.AnimationExtKt$animValues$$inlined$apply$lambda$2.onAnimationEnd(AnimationExt.kt:67)
at android.animation.Animator$AnimatorListener.onAnimationEnd(Animator.java:554)
at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1250)
at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1492)
at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:146)
at android.animation.AnimationHandler.access$100(AnimationHandler.java:37)
at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:54)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1074)
at android.view.Choreographer.doCallbacks(Choreographer.java:897)
at android.view.Choreographer.doFrame(Choreographer.java:822)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1061)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:8057)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
Have simple code:
and fun for calendar create and show.
In this case if quick tap on button (
button2
in my activity) for several times i got crash with this error: