Grouped ListView - can you detect when the group header is selected/tapped?

JasonAwbreyJasonAwbrey USInsider, University, Developer Group Leader mod

Using a Grouped ListView, is there a way to detect when the group header is selected or tapped?

Best Answer

Answers

  • EricMaupinEricMaupin USXamarin Team Xamurai

    Not currently. I'm curious what the use case for that is?

  • JasonAwbreyJasonAwbrey USInsider, University, Developer Group Leader mod

    Say you have a list of employees grouped by department. Selecting an Employee will take you to an employee detail view; selecting a Department (the group header) will take you to a Department detail view.

  • MattButlerMattButler USUniversity ✭✭

    Was anything ever resolved around this? My use case is this. I have list of records that are grouped by date, date is always shown for the period. From this listview, I can add/edit/delete a particular record. Initially, the listview will only show headers (dates) with no items. When I want to add a new item, I want to be able to click on the header (the date) to push the screen to add a new item. Its a MUCH better use of the screen to tap the group header for a new record, rather than have an tappable/clickable item to add a new item. See Attached image...

  • JasonAwbreyJasonAwbrey USInsider, University, Developer Group Leader mod

    I ended up working around it by creating a custom cell for the header with a button on it

  • MattButlerMattButler USUniversity ✭✭

    I seem to have found a way through the woods using a GesterRecognizer and it seems to work. Now if I could just get forums.xamarin.com/discussion/24827/ios8-bug-observable-collection-listview-itemsource-binding-not-consistant#latest to work, I could test it on iOS8 for consistency. This is a little funky, that it bindings into the ObservableCollection, but its doing what I need.

            <ListView.GroupHeaderTemplate>
              <DataTemplate>
                <ViewCell>
                  <StackLayout Padding="5,0,0,0" VerticalOptions="StartAndExpand" Orientation="Vertical">
                    <Label Text="{Binding PeriodDate}" YAlign="Center" Font="Large"/>
                    <Label.GestureRecognizers>
                      <TapGestureRecognizer
                          Command="{Binding OpenNewRecForPeriod}"
                            CommandParameter="{Binding PeriodDate}"/>
                    </Label.GestureRecognizers>
                  </StackLayout>
                </ViewCell>
              </DataTemplate>
            </ListView.GroupHeaderTemplate>
    
  • stechmannstechmann USMember
    edited January 2016

    I have a similar scenario / requirement as Jason and Matt. Is there an easy solution?

  • hi Jason and Matt

    Could you please share your code of custom cell view which works ?

    My requirement is to have a button in the group header. When user clicks on the button, I need to take an action of all the items of that group. Please note that if I need an action to be taken for all the items in the list, I would have a button at the page level. In this case I need to take action only for the group whose button has been clicked by the user.

    Any help appreciated.

    Thanks

    -Kalpesh

  • GillieGillie NLMember

    I have a similar scenario as Kalpesh. Is there a solution for this?

  • Xami3Xami3 PKMember, University ✭✭✭

    well if you guys are going for ListView grouping you can introduce a tap gesture or someking of button in template and then subscribe to that tap event.

    i considered the above but with time i regret it. now what we are doing is created two type of items (simple c# classes for my data items)
    1. Group item
    2. ListItem

    then based on item we switch the item template(used data template selector).

    By default we only show header items in observable collection. once a group item is tapped then we populate/insert those child items in listview and remove other listItems which are from different group

Sign In or Register to comment.