Link to home
Start Free TrialLog in
Avatar of dolphin King
dolphin King

asked on

firemonkey Android Listview Sort items

can i resort items in listview on Firemonkey ?
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

With using (Delphi) Help example for sorting (using Generics):
uses System.Generics.Defaults;
...
procedure TForm1.ButtonSortClick(Sender: TObject);
var
  Comparer: IComparer<TListViewItem>;
begin
  Comparer := TDelegatedComparer<TListViewItem>.Create(
    function(const LeftItm, RightItm: TListViewItem): Integer
    begin
      { Consider the strings as numbers and return }
      { a comparison between them. }
      Result := CompareText(LeftItm.Text, RightItm.Text);
    end);

  ListView1.Items.Sort(Comparer);
end;

Open in new window

Avatar of dolphin King
dolphin King

ASKER

but how i can retrieve the Tlistview data with this function ? should i define Leftitm,Rightitm = listview1.items ?
This is universal code ... Sort will trigger comparing (all items) and Comparer is algorithm only how Items should compare... Try it.
but the compare will not be based on text it will be based on data that equals to numbers
How you store those numbers to Data part of Item?
as example
listview item add
item.data['number'] := 10
ASKER CERTIFIED SOLUTION
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial