Android Tutorial [B4X] B4XPlusMinus - Spinner / wheel alternative

B4XPlusMinus is a cross platform control introduced in XUI Views v2.05: https://www.b4x.com/android/forum/threads/b4x-xui-views-cross-platform-views-and-dialogs.100836/



As you can see in the above image it supports three different formations: horizontal, vertical and bottom. The bottom formation is useful with smaller controls to prevent the user finger from hiding the value.

There are two ways to set the values:

SetStringItems - A list or array with the items:
B4X:
pm.SetStringItems(Array("aaa", "bbb"))
SetNumericRange - A numeric range:
B4X:
pm.SetNumericRange(1, 100, 2) '1 - 100 with interval of 2.

Numeric values are converted to strings with the help of B4XFormatter.
The controls color and text size is set with the designer. Other options:


Cyclic - Whether to move to the first item after the last item.
Rapid - Whether to allow rapid changes with long clicks. Note that you can change the durations used for the rapid effect (RapidPeriod1 and RapidPeriod2 fields - default values are 1000ms and 30ms).

Example is attached.
 

Attachments

  • B4XPlusMinusExample.zip
    11.8 KB · Views: 1,800

Alexander Stolte

Expert
Licensed User
Longtime User
i have this error on the example:
B4X:
java.lang.RuntimeException: java.lang.RuntimeException: Field b4xplusminus1 was declared with the wrong type.
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
    at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
    at b4a.exampleggsdg.main._activity_create(main.java:348)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at b4a.exampleggsdg.main.afterFirstLayout(main.java:104)
    at b4a.exampleggsdg.main.access$000(main.java:17)
    at b4a.exampleggsdg.main$WaitForLayout.run(main.java:82)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6863)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.RuntimeException: Field b4xplusminus1 was declared with the wrong type.
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:431)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:454)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:148)
 

Mahares

Expert
Licensed User
Longtime User
I downloaded: B4X Views but the library pane still shows: version 2.00 after refresh
EDIT: I had it in the additional lib folder. All is good now
 

Alexander Stolte

Expert
Licensed User
Longtime User
Can you post the unfiltered logs?

Have you copied it to the internal libraries folder?
Yes
 

RWK

Member
Licensed User
Got it working in B4J

B4X:
Sub Process_Globals
    Private fx As JFX
    Private mainForm As Form
    Private B4XPlusMinus1 As B4XPlusMinus
    Private B4XPlusMinus2 As B4XPlusMinus
    Private B4XPlusMinus3 As B4XPlusMinus
    Private B4XPlusMinus4 As B4XPlusMinus
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    mainForm = Form1
    mainForm.RootPane.LoadLayout("frmMain") 'Load the layout file.
    mainForm.Show
    
    B4XPlusMinus1.SetStringItems(File.ReadList(File.DirAssets, "cities.txt"))
    B4XPlusMinus1.Increment
    
    Dim clrs As List
    clrs.Initialize
    clrs.Add("Red")
    clrs.Add("Green")
    clrs.Add("Blue")
    B4XPlusMinus2.SetStringItems(clrs)
    B4XPlusMinus2.SelectedValue = clrs.Get(0)
    B4XPlusMinus3.SetNumericRange(0, 100, 1)
    B4XPlusMinus4.Formatter.GetDefaultFormat.MaximumFractions = 2
    B4XPlusMinus4.Formatter.GetDefaultFormat.MinimumIntegers = 2
    B4XPlusMinus4.Formatter.GetDefaultFormat.MinimumFractions = 2
    B4XPlusMinus4.SetNumericRange(0, 10, 1 / 3)
End Sub

Is the expected way to copy the b4x internal lib in each of the internal libraries folder...b4a, b4j, b4i
or better to remove internal libraries and put it in additional b4x ?

Ähmm....Nope Question:
How to assign b4xPlusMinus1 directly to the....say... third city in this case?

Grüße
Rainer
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Is the expected way to copy the b4x internal lib in each of the internal libraries folder...b4a, b4j, b4i
Yes. The good news is that the latest version will be included when the IDE is updated.

How to assign b4xPlusMinus1 directly to the....say... third city in this case?
B4X:
Dim cities As List = File.ReadList(File.DirAssets, "cities.txt")
B4XPlusMinus1.SetStringItems(cities)
B4XPlusMinus1.SelectedValue = cities.Get(2)
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
it would be interesting to add long press for automatic increased or decreised.
 

jimmyF

Active Member
Licensed User
Longtime User
It's there already! Press and hold, in the sample from the first post
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
it would be interesting to add long press for automatic increased or decreised.

Rapid - Whether to allow rapid changes with long clicks. Note that you can change the durations used for the rapid effect (RapidPeriod1 and RapidPeriod2 fields - default values are 1000ms and 30ms).
 

andyp

Member
Licensed User
Hi

For anyone looking: Visibility is controlled by: B4XPlusMinus1.mBase.Visible = False (or Ture)

Works really well thank you!
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…