Just starting out? Need help? Post your questions and find answers here.
khalidel
 
Posts: 1
Joined: Sun May 05, 2019 8:19 pm

buttons on android app

by khalidel Sun May 05, 2019 8:35 pm

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.
User avatar
Peter
 
Posts: 596
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: buttons on android app

by Peter Sun May 05, 2019 9:08 pm

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())
Return to Coding Questions

Who is online

Users browsing this forum: No registered users and 4 guests