Page 1 of 1

buttons on android app

Posted: Sun May 05, 2019 8:35 pm
by khalidel
hello friends, am new user of spiderbasic. when i create an android app with more than one button, the whole buttons reffer to the last callback in the code. sample code

Code: Select all


Declare pls()
Declare mns()


CloseDebugOutput()

Procedure pls()
v1 = Val(GetGadgetText(1))
v2 = Val(GetGadgetText(3))
v3.f = v1+v2
SetGadgetText(1, StrF(v3,2))
SetActiveGadget(1)
EndProcedure

Procedure mns()
v1 = Val(GetGadgetText(1))
v2 = Val(GetGadgetText(3))
v3.f = v1-v2
SetGadgetText(1, StrF(v3,2))
SetActiveGadget(1)
EndProcedure

  OpenWindow(0, 0, 0, 350, 600, "Calculatrice", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

TextGadget(0, 10, 10, 200, 30, "valeur1")
StringGadget(1, 100, 10, 250, 30, "")
TextGadget(2, 10, 40, 200, 30, "valeur2")
StringGadget(3, 100, 40, 250, 30, "")
ButtonGadget(4, 10, 100, 200, 30, "Plus")
ButtonGadget(5, 100, 100, 250, 30, "Moins")

BindGadgetEvent(4, @pls())
BindGadgetEvent(5, @mns())



; IDE Options = SpiderBasic 2.21 (Windows - x86)
; CursorPosition = 48
; FirstLine = 19
; Folding = -
; iOSAppOrientation = 0
; AndroidAppName = calculatrice
; AndroidAppVersion = 1.2.0
; AndroidAppPackageID = com.khalidel.clc
; AndroidAppOutput = calcul.apk
; AndroidAppOrientation = 0
; AndroidAppFullScreen
; AndroidAppEnableDebugger
; EnableXP
; CompileSourceDirectory
both buttons, plus and moins reffer to mns() procedure. i want plus button to get pls() callback and moins button to get mns() callback. thank you a lot.

Re: buttons on android app

Posted: Sun May 05, 2019 9:08 pm
by Peter
khalidel wrote:both buttons, plus and moins reffer to mns() procedure.
No, they don't, as you can see from this example:

Code: Select all

Procedure pls()
  Debug("pls")
EndProcedure

Procedure mns()
  Debug("mns")
EndProcedure

OpenWindow(0, 0, 0, 350, 600, "Calculatrice", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

TextGadget(0, 10, 10, 200, 30, "valeur1")
StringGadget(1, 100, 10, 250, 30, "")
TextGadget(2, 10, 40, 200, 30, "valeur2")
StringGadget(3, 100, 40, 250, 30, "")
ButtonGadget(4, 10, 100, 160, 30, "Plus")
ButtonGadget(5, 180, 100, 160, 30, "Moins")

BindGadgetEvent(4, @pls())
BindGadgetEvent(5, @mns())