Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Detecting grouped header key in a Listview with FastScroll

$
0
0

Is there any way to detect the grouped header key when i released the bar of FastScroll in a Listview?

This is my scenario:

Im using a grid with pics of employees and beside of it I have a listview with the Android "FastScroll" feature enabled. I need to swipe over the grouped Listview (bar) and when i released it, get the current key to show a "check" image over the employees pics. Searching about how to get it i found that a ViewCell is needed, can anyone explain to me how to do that?

My code:

(viewcell)

    public class GroupHeaderCell : ViewCell
        {
            public GroupHeaderCell ()
            {
                Height = 40;

                var groupKey = new Label
                {
                    FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                    TextColor = Color.White,
                    VerticalOptions = LayoutOptions.Center
                };
                groupKey.SetBinding(Label.TextProperty, new Binding("Key"));

                StackLayout View = new StackLayout
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    HeightRequest = 40,
                    BackgroundColor = Color.FromRgb(255, 153, 0),
                    Padding = 5,
                    Orientation = StackOrientation.Horizontal,
                    Children = { groupKey }
                };

                var tapGestureRecognizer = new TapGestureRecognizer();
                tapGestureRecognizer.Tapped += (s, e) => {
                    var sender = s;
                };
                View.GestureRecognizers.Add(tapGestureRecognizer);

            }
    }


(xaml.cs)
         private void CreateIndexList()
                {
                var template = new DataTemplate(typeof(TextCell));
                    template.SetBinding(TextCell.TextProperty, ".");
                    IndexList.ItemTemplate = template;
                    IndexList.GroupHeaderTemplate = new DataTemplate(typeof(GroupHeaderCell));
                    IndexList.Margin = new Thickness(0, 0, 0, 0);
                    IndexList.IsGroupingEnabled = true;
                    IndexList.GroupDisplayBinding = new Binding("Key");
                    IndexList.GroupShortNameBinding = new Binding("Key");
                    IndexList.On<Xamarin.Forms.PlatformConfiguration.Android>().SetIsFastScrollEnabled(true);
                    var source = new List<string>();
                    for (int count = 200; count > 0; --count)
                    {
                        source.Add(RandomString.Generate(5));
                    }
                    IndexList.ItemsSource = new List<IGrouping<string, string>>(
                        source.OrderBy(x => x).GroupBy(x => x[0].ToString().ToUpper())
                    );
                }

Im using this url as reference https://github.com/xamarin/Xamarin.Forms/issues/1481

I don't really need the items from the listview, the grouped header keys only to detect second names and check pics.

Any help is welcome.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>