B4J Question Spinner

red30

Well-Known Member
Licensed User
Longtime User
I use Spinner. When I entered a new value in Spinner.Value nothing changes until I press Enter. Can I react to changes in the value of Spinner.Value without pressing the Enter key?
 

red30

Well-Known Member
Licensed User
Longtime User
No, I mean Spinner.
upload_2017-4-27_21-16-17.png
 
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
I use 18 spinners. I enter values to each of them and after, pushing the button, i send them at once. I dont want to push Enter after each value.
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
I made a small example with a button changing the Spinner value and worked without any other input

also changed the editable property to true and manually changed the value and it was modified.

how are you changing the values?
 
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
I change values with the keyboard. But they dont change untill i push Enter.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Are you using
B4X:
Sub spinner_ValueChanged (Value As Object)
...
End Sub
To detect the value ?
If so use
B4X:
Sub spinner_ValueChanged(Value as Object) ' wont get triggered without Enter or control losing focus
    doSomethingWith(spinner.Value)      ' Ignore the Value in ValueChanged use this instead
End Sub
This reflects the current spinner value - the ValueChanged(...) doesn't update until enter is pressed.
 
Last edited:
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
Are you using
B4X:
Sub spinner_ValueChanged (Value As Object)
...
End Sub
To detect the value ?
If so use
B4X:
Sub spinner_ValueChanged(Value as Object) ' wont get triggered without Enter or control losing focus
    doSomethingWith(spinner.Value)      ' Ignore the Value in ValueChanged use this instead
End Sub
This reflects the current spinner value - the ValueChanged(...) doesn't update until enter is pressed.
I do not understand, give me small example...
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Have a look at this example. I think I understand what you are trying to do.

Changing the value of spinner 1 or 2 via the keyboard without pressing enter does not fire the change event. Changing spinner 1 without enter and then focus on spinner 2 does not fire the change event for spinner 1 either. The button copies the values from the spinners to the labels. This is the way the spinner works.

For the moment I can see no workaround to do what you want. Sorry. The only way seems to press enter.
 

Attachments

  • test.zip
    2.3 KB · Views: 238
Last edited:
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Edit: If you change the spinners to Textfields, then the TextChanged event will fire when you enter text manually from the keyboard. If you still want to use up and down arrows like the spinner has, maybe you can use two buttons for this and create a radiobutton/textfield array to select and change the required item. Hope this helps a little.
 

Attachments

  • test1.zip
    2.5 KB · Views: 188
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
mark35at, Thanks a lot, you ve understood me truly in post9.
As for textfield, is it possible to enter only numbers there?
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
I could imagine that when the focus is lost, there is an event called (not on my pc, so i cannot check). You could use this to validate the input and if is not just a number, return the focus and delete the text or show a messagebox.
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Attached a possible solution using JavaFX API methods (require the JavaObject library)
The way this example works is
  • make the spinner editable
  • create for the textfield of spinner an eventhandler for key released
  • the key released event gets the value from the spinner textfield and shows it in a label
  • please note: there is no error handling, ie handle an empty textfield. the sub appinit to be called in appstart.
Code Snippet from attached example
B4X:
Sub Process_Globals
    Private Spinner1 As Spinner
...

Sub AppInit
    Spinner1.Editable = True
    Dim joSP As JavaObject = Spinner1
    Dim joTF As JavaObject = joSP.RunMethod("getEditor", Null)
    Dim oTF As Object = joTF.CreateEvent("javafx.event.EventHandler","TextFieldKeyReleased",False)
    joTF.RunMethod("setOnKeyReleased",Array(oTF))
    Label1.Text = Spinner1.Value
End Sub

Private Sub TextFieldKeyReleased_Event(EventName As String,Args() As Object) As Object
    Dim joSP As JavaObject = Spinner1
    Dim tf As TextField = joSP.RunMethod("getEditor", Null)
    Label1.Text = tf.Text
    Return False
End Sub

Sub Spinner1_ValueChanged (Value As Object)
    Label1.Text = Value
End Sub
 

Attachments

  • SpinnerKeyControl.zip
    2.2 KB · Views: 229
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
And can you somehow automatically press Enter?

B4X:
Spinner1.RequestFocus
And then press Enter
 
Upvote 0
Top