It wraps this Github project. It requires android-support-v4.jar (a recent version) to be in your additional library folder. You can download it from here. Posting the B4A project, the B4A library files, and the Java code. If you want to make changes to the Java code and recompile it you must add android-support-v4.jar to the libs folder (libs folder is on the folder level as the src folder - see folder structure once you have extracted the zipped file).
The spinner has a nice animated arrow when the spinner opens/closes. You can set amongst others the following:
1. The background color of the selected text
2. The text color of the selected text
3. The background color of the dropdown list
4. The text color of the text in the dropdown list
5. The divider height (between entries) in the dropdown list
6. The color of the divider between entries in the dropdown list (specify 3 different colors or 3 colors of the same color)
Upon selection an event is raised in the B4A project where you can the extract the index of the selected item (first item in a list = index(0)).
Some sample code:
NiceSpinner
Author: Johan Schoeman
Version: 1
The spinner has a nice animated arrow when the spinner opens/closes. You can set amongst others the following:
1. The background color of the selected text
2. The text color of the selected text
3. The background color of the dropdown list
4. The text color of the text in the dropdown list
5. The divider height (between entries) in the dropdown list
6. The color of the divider between entries in the dropdown list (specify 3 different colors or 3 colors of the same color)
Upon selection an event is raised in the B4A project where you can the extract the index of the selected item (first item in a list = index(0)).
Some sample code:
B4X:
#Region Project Attributes
#ApplicationLabel: NiceSpinner
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private ns1, ns2 As NiceSpinner
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")
ns1.Initialize("ns1")
ns2.Initialize("ns2")
Activity.AddView(ns1, 20%x, 5%y, 20%x, 10%y)
Activity.AddView(ns2, 60%x, 5%y, 20%x, 10%y)
Dim r1 As List
r1.Initialize
r1.AddAll(Array As String("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve"))
Dim divcolor() As Int = Array As Int(Colors.Blue, Colors.Green, Colors.Red)
ns1.DividerColor = divcolor
ns1.DividerHeight = 1
ns1.DropdownListBackgroundColor = Colors.LightGray
ns1.attachDataSource(r1)
ns1.DropdownListTextColor = Colors.DarkGray
'the next two lines of code must be before ns1.SelectedIndex is set
ns1.SelectedTextColor = Colors.Green
ns1.SelectedTextBackgroundColor = Colors.White
'always set this even if just to 0
ns1.SelectedIndex = 0
Dim r2 As List
r2.Initialize
r2.AddAll(Array As String("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"))
Dim divcolor() As Int = Array As Int(Colors.White, Colors.White, Colors.White)
ns2.DividerColor = divcolor
ns2.DividerHeight = 2
ns2.DropdownListBackgroundColor = Colors.Black
ns2.attachDataSource(r2)
ns2.DropdownListTextColor = Colors.White
'the next two lines of code must be before ns2.SelectedIndex is set
ns2.SelectedTextColor = Colors.White
ns2.SelectedTextBackgroundColor = Colors.DarkGray
'always set this even if just to 0
ns2.SelectedIndex = 2
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub ns1_item_clicked
Log("ns1 item " & ns1.SelectedIndex &" selected")
End Sub
Sub ns2_item_clicked
Log("ns2 item " & ns2.SelectedIndex &" selected")
End Sub
NiceSpinner
Author: Johan Schoeman
Version: 1
- NiceSpinner
Fields:- ba As BA
- BringToFront
- DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
- Initialize (EventName As String)
- Invalidate
- Invalidate2 (arg0 As Rect)
- Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
- IsInitialized As Boolean
- RemoveView
- RequestFocus As Boolean
- SendToBack
- SetBackgroundImage (arg0 As Bitmap)
- SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
- SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
- SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
- SetTextColorAnimated (arg0 As Int, arg1 As Int)
- SetTextSizeAnimated (arg0 As Int, arg1 As Float)
- SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
- attachDataSource (dataset As List)
- dismissDropDown
- showDropDown
- Background As Drawable
- Color As Int [write only]
- DividerColor() As Int [write only]
- DividerHeight As Int [write only]
- DropdownListBackgroundColor As Int [write only]
- DropdownListTextColor As Int [write only]
- Enabled As Boolean
- Gravity As Int
- Height As Int
- Left As Int
- SelectedIndex As Int
Get or Set the default spinner item using its index - SelectedTextBackgroundColor As Int [write only]
- SelectedTextColor As Int [write only]
- Tag As Object
- Text As String
- TextColor As Int
- TextSize As Float
- Top As Int
- Typeface As Typeface
- Visible As Boolean
- Width As Int
Attachments
Last edited: