Jump to content
sjordi

TListView swipe in both directions?

Recommended Posts

Hi,

The TListView component offers just a swipe left to display the Delete button.

While it's possible to customize the text with something else, it fires an event only to an Item "swipe left".

 

I'd like to be able to swipe both directions, right and left, in order to check/uncheck (select/unselect) the current item.

Any way to easily implement this? Or any available FMX component (even paid) that extends/derives from TListViews?
Thanks for any help and suggestion

 

Edited by sjordi

Share this post


Link to post

hi @sjordi

FMX: I have tested on "MSWindows - mouse" and "Android 11 - finger" and I can delete the item using "Left or Rigth" direction.

  • Note: if "deleting by code" needs hide the delete button on next item showed on ListView after item-deleted!
type
  TForm1 = class(TForm)
    ListView1: TListView;
    GestureManager1: TGestureManager;
....
var
  LastLI: TListItem = nil; // to avoid many times in same item...

procedure TForm1.FormCreate(Sender: TObject);
begin
  for var i: integer := 0 to 9 do
      ListView1.Items.Add.Text := 'Item' + i.ToString;
end;

procedure TForm1.ListView1Gesture(Sender: TObject; const EventInfo: TGestureEventInfo; var Handled: Boolean);
var
  LI: TListItem;
begin
  Handled := true; // YOU on control!
  //
  //if GestureToIdent(EventInfo.GestureID, s) then Memo1.Lines.Add(EventInfo.GestureID.ToString + '=' + s);
  //
  case EventInfo.GestureID of
    sgiLeft, sgiRight:
      begin
        // ... delete it? or let the user click on "Delete button"
        LI := ListView1.Selected;
        //
        if (LI <> nil) and (LI <> LastLI) then
          begin
            ListView1.Items.Delete(LI.Index); // or other action...
            //
            LastLI := LI;
          end;
      end;
  end;

 

Edited by programmerdelphi2k

Share this post


Link to post

Thank you. That seems to work.
I have to combine this now with my OnItemClickEX event and see whether we can combine that.

Also the problem is that the item is not moving. I'll see whether it's possible to make the Item itself slide right or left so the user can visually see what happens.

 

Thanks a lot for your example, this is of huge help.

Steve

Share this post


Link to post

Ok I tried this but I can't attach the animation to an item. Maybe I'm missing something.

I guess I have to do it programmatically by adding it to a TListViewItem.

I'll post back here if I succeed. 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×