Android Question Action Up Event on Calculator

Tim5000

Member
Licensed User
Longtime User
Hello Everyone!
I have a simple calculator using panels for the buttons. I am using Action_Down and Action_up to load Normal and pressed images. This all works fine.

My question is... In most apps when you press a button then slide your finger off to the side, the action is cancelled. In other words the Action_up event never fires. This is what I want to happen, but in B4A doing this with panels or even with buttons it does not work, you can slide your finger off the button and the Action_Up code runs as soon as you lift your finger. Am I missing something, or is there a specific code needed to get this behavior?
 

mangojack

Expert
Licensed User
Longtime User
Tim .. if you still wish to proceed that way maybe this could be of use. You will have to experiment with deviation values.

B4X:
Sub Panel1_Touch(Action As Int , X As Float, Y As Float)

  Dim startX , startY As Int
  Select Action
    Case 0    'Down
       startX = X
       startY = Y
    Case 1   'Up
      If Abs(X - startX) > 20%x OR Abs(Y - startY) > 30%y Then Return  'consume action
   
      'your code ....... 
  End Select

End Sub
 
Last edited:
Upvote 0

Tim5000

Member
Licensed User
Longtime User
The standard action is Click not Up. It will behave as you described.

Have you seen AnotherDatePicker class?

Thanks Erel! Yes, I see the click does the job. But when using click I lose the ability to display one bitmap on Action_Down, and a different bitmap on Action_Up
 
Upvote 0

Tim5000

Member
Licensed User
Longtime User
Tim .. if you still wish to proceed that way maybe this could be of use. You will have to experiment with deviation values.

B4X:
Sub Panel1_Touch(Action As Int , X As Float, Y As Float)

  Dim startX , startY As Int
  Select Action
    Case 0    'Down
       startX = X
       startY = Y
    Case 1   'Up
      If Abs(X - startX) > 40%x OR Abs(Y - startY) > 20%y Then Return  'cancel action  
     
      'your code .......   
  End Select

End Sub


Thanks MangoJack! I am going to try it now. Will post results soon!
 
Upvote 0
Top