Group record(item) counting listview grouping

3 posts, 0 answers
  1. Paul
    Paul avatar
    6 posts
    Member since:
    Jul 2012

    Posted 16 Mar Link to this post

    Following the examples provided in the documention for grouping addGroupDescriptor(groupDescriptor) work perfectly.

    What I would like to do is in the groupitem display groupheader and give the total count of the items in the group i.e. getItemCount.

    Is this done in "public void onBindGroupViewHolder(ListViewHolder holder, Object groupKey)" in the DataSourceAdapter?

    If you could provide code snipped as to achieve this it would be appreciated.

  2. Todor
    Admin
    Todor avatar
    778 posts

    Posted 18 Mar Link to this post

    Hi Paul,

    Thank you for your question.

    You are right about the place to do this - onBindGroupViewHolder - this is where you need to set the desired text, based on the value of the group that is passed as a parameter. Using this value, you can get the position of the group header in the list using the method getPosition. This position will allow you to get the dataItem that holds the group info. The count of the items in the group is contained in that group info. Here's the modified version of the method from the documentation that will allow you to set this information to the group header:

    @Override
    public void onBindGroupViewHolder(ListViewHolder holder, Object groupKey) {
        int itemPosition = getPosition(groupKey);
        DataItem dataItem = getDataItem(itemPosition);
        int itemsCount = dataItem.getItems().size();
        ((ListViewTextHolder)holder).textView.setText(String.valueOf(itemsCount));
    }

    Let us know if you need further assistance.

    Regards,
    Todor
    Telerik
    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. DevCraft banner
  4. Paul
    Paul avatar
    6 posts
    Member since:
    Jul 2012

    Posted 21 Mar in reply to Todor Link to this post

    Thank you.  Your post is perfect and works 100%.
Back to Top