i am trying a simple code to get the value from the seekbar but it seem like im only getting value 50 no matter how i trigger the seekbar.
code are as below
Sub Globals
Dim Label1 As Label
Dim SeekBar1 As SeekBar
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
Label1.Text=SeekBar1.Value
End Sub
anything i have done wrong ??
The reason this does not work for you, is Sub Activity_Create is called at the very start of the app, or when the activity is destroyed and recreated, like when you tilt the device on the side. When Activity_Create is called, the value of Seekbar is 50. it hasn't been updated or changed yet, because the app is just starting up.
Sub SeekBar1_ValueChanged (Value As Int, UserChanged As Boolean)
End Sub
Sub button1_down
Label1.Text=SeekBar1.Value
End Sub
i wan to see the value of seekbar when im pressing the button. which mean when i pressing the button and toggle the seekbar at the same time , the value will keep on changing. Unfortunately, i have try the event of click,up,down,long click , none of them working...
any idea ???
It's very odd that you want to see the value of a seekbar while you are holding down a button. But... you asked, so I will answer. Look at this code. It is very simple, very straightforward and it works. I leave any dressing up or further processing to you...
Sub Process_Globals
End Sub
Sub Globals
Dim Button1 As Button
Dim Seekbar1 As SeekBar
Dim Label1 As Label
Dim isButtonDown As Boolean = False
End Sub
Sub Activity_Create(FirstTime As Boolean)
Button1.Initialize("Button1")
Button1.Text = "Show"
Seekbar1.Initialize("Seekbar1")
Label1.Initialize("")
Label1.Color = Colors.Gray
Activity.AddView(Button1, 40%x, 30%y, 20%x, 10%y)
Activity.AddView(Seekbar1, 10%x, 10%y, 80%x, 5%y)
Activity.AddView(Label1, 40%x, 60%y, 20%x, 10%y)
End Sub
Sub Button1_down
isButtonDown = True
End Sub
Sub Button1_up
isButtonDown = False
End Sub
Sub Seekbar1_ValueChanged (Value As Int, UserChanged As Boolean)
If isButtonDown = True Then
Label1.Text = Value
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Here is the explanation of what is happening:
In Sub Globals a button, seekbar and label are defined (sorry, I don't use layouts, I create views manually and this is how it's done). Also, a true/false boolean flag is defined to indicate to the seekbar event if the button is currently pressed down or not.
In Sub Activity_Create, these views are initialized and other properties are assigned, like the button text and label color. Then they are added to the acitivity.
Sub Button1_Down simple sets isButtonDown boolean flag variable to true, indicating it is pressed down. Button1_down is called only when the button is first pressed down, not during the entire time it is held down.
Sub Button1_Up sets the variable isButtonDown to false. It is called when the button is first unclicked or let up on.
Sub Seekbar1_ValueChanged is where the magic is. Note that this event sub is called every time the position value of the seekbar is changed, even it it's only by 1. So, as you scroll the seekbar's button across the screen, it can be called hundreds of times. Each time it is called, it checks to see if the button is being held down by checking the boolean variable isButtonDown. If it is True, then the button is being held down, and it sets the value of the seekbar position to the label text (we don't need to say seekbar1.value because 'value' is passed as a parameter, but you can use seekbar1.value if you wish)
That's all there is to it. The hard part is a basic understanding of how android handles views and their event subs, and how to make the different components all work together for the desired end result. Since you seem very new to Basic4android, I suggest you further that basic understanding of android and how its components work and work together. Keep reading the documentation and beginner tutorials. Trying to run before you can walk leads to much frustration. Coding should be fun and enjoyable
Jesse