Jump to content
Sign in to follow this  
NecoArc

how to avoid 'double click' event on the screen in mobile

Recommended Posts

I have a situation that occurs on low-end Android devices.

Short version: When the user double-taps a button, the event is being executed on the button that hasn't been created on the screen yet.

What happens is, I have a list of frames created on my screen, which represent the product categories.

When I tap on a category frame, the application destroys the category frames on the screen and creates a new set of product frames.

The problem is, when my user double-taps very quickly on the category frame, the second click is executed on the product frame that hasn't even appeared on the screen yet.
I'm using delphi 12.2

 

My code is something like this:



 

procedure CreateCategory;
var
  frm: TFrameCategory;
  category: TObjCategory;
begin
  for category in listCategory do
  begin
    frm := TFrameCategory.Create(nil, category);

    frm.OnClick := OnClickCategory;

    rectangleFrames.AddObject(frm);  
  end;  
end;

procedure OnClickCategory(Sender: TObject);
var
  frm: TFrameProduct;
  prod: TObjProduct;
  i: Integer;
begin
  for i := rectangleFrames.ControlsCount - 1 downto 0 do
  begin
    rectangleFrames.Controls.DisposeOf;
  end;
  rectangleFrames.ControlCollection.Clear;

  for prod in listProduct do
  begin
    frm := TFrameProduct.Create(nil, prod);

    frm.OnClick := OnClickProduct;

    rectangleFrames.AddObject(frm);  
  end;
end



 

So, the second tap is executed in OnClickProduct instead of being executed twice in OnClickCategory.

How can I prevent this?
i've alredy tryed a lot of things like calling this procedure on the OnClickCategory event but it doesn't seems ideal 


 

procedure disableRecTemp;
begin
 rectangleFrames.Enabled:= False;
  TThread.CreateAnonymousThread(procedure
  begin
    Sleep(1500);
    TThread.Synchronize(nil, procedure
    begin
      rectangleFrames.Enabled := True;
    end);
  end).Start;

end


 

Edited by NecoArc

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
Sign in to follow this  

×