Applandeo / Material-Calendar-View

Material Calendar View for Android
Apache License 2.0
975 stars 316 forks source link

Cannot display calendar in Recycler View #422

Closed ZeeOne closed 1 year ago

ZeeOne commented 2 years ago

Similar to the issue mentioned below, if I put the calendar in a recycler view, then it refuses to display the days part, until you press the next button.

My adapter looks like `public class HeaderAdapter extends RecyclerView.Adapter {

Context context;

public HeaderAdapter(Context context) {
    this.context = context;
}

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    return new CalendarFilterAdapter.ViewHolder(LayoutInflater.from(context).inflate(R.layout.content_calendar_header,
            parent, false)
    );
   // return new RecyclerView.ViewHolder(inflate.inflate(R.layout.content_calendar_header, parent, false));
}

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
}

@Override
public int getItemCount() {
    return 1;
}

}`

my layout file like: <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content"> <com.applandeo.materialcalendarview.CalendarView android:id="@+id/calendarView" android:layout_width="match_parent" android:layout_height="wrap_content" app:headerColor="@color/background" app:headerLabelColor="@color/black" app:type="one_day_picker" app:previousButtonSrc="@drawable/ic_leftcircle" app:forwardButtonSrc="@drawable/ic_rightcircle" app:abbreviationsBarColor="@color/background" app:selectionColor="@color/primary" app:selectionLabelColor="@color/white" app:todayLabelColor="@color/primary"/> </androidx.coordinatorlayout.widget.CoordinatorLayout>

And it gets displayed in a fragment, as part of concat adapter, like so: HeaderAdapter headerAdapter = new HeaderAdapter(getContext()); mAdapter = new CalendarFilterAdapter(getContext(), taskEntries);

If the user rotates the device, it hides itself again.

@mateuszSawa can you please reopen this issue? I have the same issue when placing calendar in RecyclerView. Wrapping calendar in ConstraintLayout does not help

Here is my RecyclerView ViewHolder for calendar:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:android="http://schemas.android.com/apk/res/android">

    <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <com.applandeo.materialcalendarview.CalendarView
                android:id="@+id/calendarView"
                app:type="one_day_picker"
                app:eventsEnabled="true"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

And here is how it looks like: image

Originally posted by @fedyiv in https://github.com/Applandeo/Material-Calendar-View/issues/129#issuecomment-827404774

aniketpatil2890 commented 1 year ago

Facing same issue, not working inside Recycler view with Concat adapter, tried ConstraintLayout, CoordinatorLayout. Any other solution ?

kormateusz commented 1 year ago

Fixed in 1.9.0-rc6