question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calendar does not appear

See original GitHub issue

I followed all instructions but for some reason the calendar does not show. What could I be doing wrong?

`<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=“http://schemas.android.com/apk/res/android” xmlns:tools=“http://schemas.android.com/tools” android:layout_width=“match_parent” android:layout_height=“match_parent” xmlns:app=“http://schemas.android.com/apk/res-auto”>

<com.kizitonwose.calendarview.CalendarView
        android:id="@+id/calendarView"
        android:layout_width="200dp"
        android:layout_height="200dp"
        app:cv_dayViewResource="@layout/calendar_day_layout"
        android:layout_centerInParent="true"
         />

</androidx.constraintlayout.widget.ConstraintLayout>`

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kizitonwosecommented, Jan 13, 2021

@mkieczko96 You did not setup View binding properly in your initial example.

From the code you shared:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = FragmentWelcomeBinding.inflate(getLayoutInflater());
        calendarView = binding.calendarView;
}

The above code creates a view binding but in the onCreateView, you return a completely different view.

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_welcome, container, false);
}

This is how to use ViewBinding:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        binding = FragmentWelcomeBinding.inflate(getLayoutInflater());
        return binding.getRoot();
}
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
		// Use the binding here, you can also use it directly in onCreateView above.
		// binding.calendarView.........
    }
0reactions
mkieczko96commented, Jan 13, 2021

I found it!

It looks like ViewContainer doesn’t like viewBinding. When I changed my WelcomeFragment.java class to look as follows, it started working:

package com.booker.ui.fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.booker.R;
import com.kizitonwose.calendarview.CalendarView;
import com.kizitonwose.calendarview.model.CalendarDay;
import com.kizitonwose.calendarview.ui.DayBinder;
import com.kizitonwose.calendarview.ui.ViewContainer;

import org.jetbrains.annotations.NotNull;

import java.time.DayOfWeek;
import java.time.YearMonth;

public class WelcomeFragment extends Fragment {

    public WelcomeFragment() {
    }

    public static WelcomeFragment newInstance() {
        return new WelcomeFragment();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        class DayViewContainer extends ViewContainer {

            final TextView calendarDay;

            public DayViewContainer(@NotNull View view) {
                super(view);
                calendarDay = view.findViewById(R.id.calendar_day);
            }
        }

        CalendarView calendarView = view.findViewById(R.id.calendar_view);

        calendarView.setDayBinder(new DayBinder<DayViewContainer>() {
            @NotNull
            @Override
            public DayViewContainer create(@NotNull View view) {
                return new DayViewContainer(view);
            }

            @Override
            public void bind(@NotNull DayViewContainer container, @NotNull CalendarDay day) {
                container.calendarDay.setText(String.valueOf(day.getDay()));
            }
        });

        calendarView.setup(
                YearMonth.of(2020, 1),
                YearMonth.of(2022, 12),
                DayOfWeek.MONDAY
        );

        calendarView.scrollToMonth(YearMonth.now());
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_welcome, container, false);
    }
}

As you can see, I have resigned from using ViewBindings, there are some minor changes also, but I’ve checked them with no luck. As a prove:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix sync problems with the Google Calendar app - Android
Use this page if events you created or updated aren't showing on your computer or in the Google Calendar app. First, try these...
Read more >
I Can't See Calendar Appointments in Outlook
Alternatively, right-click on the calendar in the Folder Pane and then click "Show This Calendar." By default, checked calendars are displayed side-by-side. To ......
Read more >
If your iCloud Contacts, Calendars, or Reminders won't sync
Make sure that All iCloud is selected. Open the Calendar app and tap the Calendars tab.
Read more >
What to Check if Calendar Events are Not Showing
What to Check if Calendar Events are Not Showing ; Hidden sub calendars · Refresh your calendar ; Clear your browser's cache. ·...
Read more >
Outlook troubleshooting: No Outlook calendars are showing in ...
Outlook troubleshooting: No Outlook calendars are showing in the Select calendars to sync step · Quit and reboot connector · Check permission ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found