Xamarin Forms: How to remove empty space between listview items based on date?

Sreejith Sree 1,251 Reputation points
2021-03-29T08:25:18.117+00:00

I'm using listview to display the list of items. The items are getting listed based on their date. If there are multiple events in a day I need to remove the space between the events and hide the date for the items other than the first one. Now I'm hiding the date using the day visibility variable using the following code:

foreach (var eventshb in eventsHBList)
{
    bool isFirstItem = true;
    foreach (var events in eventshb.eventsList)
    {
        if (isFirstItem)
        {
            eventshb.dayVisibility = true;
            isFirstItem = false;
        }
        else
        {
            eventshb.dayVisibility = false;
        }
        eventshb.eventsListTO = events;
        EventAllItems.Add(eventshb);
    }
}

I'm trying to remove the empty space between the items. For refers, I have added the current UI and the required UI Screenshots.

The demo project using the listview for displaying the events is uploaded in the drive.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,296 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,951 Reputation points
    2021-03-29T10:54:08.43+00:00

    Hi, SreejithSree-2948. For the effect of the screenshot, try using a grouped listView to display the data. You could group the data by date.

    Related doc:
    https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/listview/customizing-list-appearance#grouping

    0 comments No comments