Closed AriMeidan closed 7 years ago
Hi @AriMeidan,
Thank you for the report.
Are you calling LightCalendarView#getMonthViewForPosition()
in an activity's onCreate()
or a fragment's onCreateView()
method? If so, move the code to somewhere like onResume()
or onViewCreated()
where the view creation and child view inflations have completed.
You can also use View#addOnLayoutChangeListener
to run your code right after the inflation completes as follows:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final LightCalendarView calendarView = (LightCalendarView) findViewById(R.id.calendar_view);
calendarView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
int positionForDate = calendarView.getPositionForDate(new Date());
MonthView monthView = calendarView.getMonthViewForPosition(positionForDate);
Log.d("MainActivity", "positionForDate = " + positionForDate + ", monthView = " + monthView);
calendarView.removeOnLayoutChangeListener(this);
}
});
}
Hope this helps.
We are closing this issue as there are no further comments coming. Feel free to reopen this issue.
Thanks!
this.getMonthViewForPosition(this.getPositionForDate(date));
returns null althoughthis.getPositionForDate(date)
is valid.