locked
How do you group and display unique items in a ListView? RRS feed

  • Question

  • User107645 posted

    Hello Everyone,

    I am trying to display different dates into a ListView. For each record I enter into the database, it creates a unique id with a corresponding date. If I entered the following:

    Item A 4/6/2015 Item B 4/6/2015 Item C 4/7/2015

    I would want the ListView to display 4/6/2015 and 4/7/2015. However my ListView displays all 3 dates.

    Not sure where to start on this one. Would I have to fix my adapter to do this?

    Here is my adapter:

        public override Android.Views.View GetView (int position, Android.Views.View convertView, Android.Views.ViewGroup parent)
            {
                // Get our object for position
                var item = tasks[position]; 
    
                //Try to reuse convertView if it's not  null, otherwise inflate it from our item layout
                // gives us some performance gains by not always inflating a new view
                // will sound familiar to MonoTouch developers with UITableViewCell.DequeueReusableCell()
                var view = (convertView ?? 
                        context.LayoutInflater.Inflate(
                        Android.Resource.Layout.SimpleListItemChecked, 
                        parent, 
                        false)) as CheckedTextView;
    
                view.SetText (item.Task == "" ? "Please update" : item.Created_date.ToString("yyyy-M-d dddd"), TextView.BufferType.Normal);
                view.Checked = item.Done;
    
                //Finally return the view
                return view;
            }
    

    Can anyone point me in the right direction, provide some resources or samples to read up on?

    Thanks

    Tuesday, April 7, 2015 12:12 AM

Answers

  • User119263 posted

    Have you tried to convert your array to a List and use Linq to use only de different dates as your list input?

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, April 7, 2015 7:22 AM

All replies

  • User24682 posted

    You could use a Set to store the items instead of an array.

    http://upshots.org/android/android-java-for-unique-collection

    Tuesday, April 7, 2015 3:13 AM
  • User119263 posted

    Have you tried to convert your array to a List and use Linq to use only de different dates as your list input?

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, April 7, 2015 7:22 AM