StickyHeader being treated as a row in list

5 posts, 1 answers
  1. Fernando
    Fernando avatar
    5 posts
    Member since:
    Dec 2013

    Posted 07 Dec 2016 Link to this post

    After including a StickyHeaderBehavior to our RadListView, the headers are not only clickable but are preventing us from capturing the correct items from our list, since each header is considered a list item.

    Adding the behavior: 

    View mainLayout = inflater.Inflate(Resource.Layout.jobs_fragment, container, false);
    jobsListView = mainLayout.FindViewById<RadListView>(Resource.Id.listView);
    jobsListView.AddBehavior(new StickyHeaderBehavior());

     

    Overriden methods:

    public override ListViewHolder OnCreateGroupViewHolder(ViewGroup parent, int viewType)
    {
        LayoutInflater inflater = LayoutInflater.From(parent.Context);
        View view = inflater.Inflate(Resource.Layout.jobs_separatorView, parent, false);
        view.SetOnClickListener(null);
        return new ListViewTextHolder(view, Resource.Id.textSeparator);
    }
     
    public override void OnBindGroupViewHolder(ListViewHolder holder, Java.Lang.Object groupKey)
    {
        string character = groupKey.ToString().Substring(0, 1);
        character = character.ToUpper();
     
        ((ListViewTextHolder)holder).TextView.Text = character;
    }

     

    The result is attached.

    Any help is much appreciated.

    Fernando

     

     

  2. Deyan
    Admin
    Deyan avatar
    2108 posts

    Posted 09 Dec 2016 Link to this post

    Hello Fernando,

    Thanks for writing.

    Group headers are indeed part of the list. This is how the ListView works. If you want to acquire the index of a data item within the list, you need to use the ListViewDataSourceAdapter.getItemPosition(Object sourceItem) method.

    Can you please elaborate further on the problem with group headers being clickable? What kind of behavior are you trying to achieve?

    Thanks!

    Regards,
    Deyan
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Fernando
    Fernando avatar
    5 posts
    Member since:
    Dec 2013

    Posted 09 Dec 2016 in reply to Deyan Link to this post

    Thank you for the quick response.

    After we add the stick headers, we are doing the following to retrieve the item that was clicked:

    private void JobItemClicked(object sender, RadListView.ItemClickEventArgs e)
            {
                if (jobs.Count > e.P0)
                {
                    Job jobitem = jobs?[e.P0];
     
                    if (jobitem != null)
                    {
                        Vm.CurrentJob = jobitem;
                        Activity.StartActivity(new Intent(Activity, typeof(JobDetailsActivity)));
                    }
                }
            }

     

    P0 is the item position on the listview. Unfortunately, this also accounts for the stick header.

     

     

  4. Answer
    Deyan
    Admin
    Deyan avatar
    2108 posts

    Posted 09 Dec 2016 Link to this post

    Hello Fernando,

    Thanks for writing back.

    You need to use the ListViewDataSourceAdapter.getItem(int position) to acquire the right data item. Does that not work for you?

    Regards,
    Deyan
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. Fernando
    Fernando avatar
    5 posts
    Member since:
    Dec 2013

    Posted 09 Dec 2016 Link to this post

    Perfect, thank you!
Back to Top