yannecer / NCalendar

一款安卓日历,仿miui,钉钉,华为的日历,万年历、365、周日历,月日历,月视图、周视图滑动切换,农历,节气,Andriod Calendar , MIUI Calendar,小米日历
Apache License 2.0
1.59k stars 314 forks source link

MonthCalendar在xml中的visibility 为gone,首次加载必然崩溃. #34

Closed 2ndtonone closed 5 years ago

2ndtonone commented 5 years ago

java.lang.NullPointerException: Attempt to invoke virtual method 'org.joda.time.LocalDate com.necer.view.BaseCalendarView.getInitialDate()' on a null object reference at com.necer.calendar.BaseCalendar.drawView(BaseCalendar.java:153) at com.necer.calendar.BaseCalendar.access$000(BaseCalendar.java:30) at com.necer.calendar.BaseCalendar$1$1.run(BaseCalendar.java:80) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

yannecer commented 5 years ago

@2ndtonone 看到这个问题,这个问题,现在只能判null,但是显示依然不正常,还没有想到好的解决方法,问题的原因是,绘制的操作是在ViewPager的OnPageChangeListener的回调中完成的,当初始时日历为GONE,调用OnPageChangeListener的方法时未初始化当前页面,当再次设为可见是,才调用adapter的实例化方法,这个时候不会调用OnPageChangeListener的方法,就造成当前页面显示不正常,后面再想下怎么解决

2ndtonone commented 5 years ago

我现在的处理是默认为visible,然后在onstart中延迟100ms再设置为gone.

yannecer commented 5 years ago

@2ndtonone 刚已经解决了,提交代码了