Simple Spinner question

cymorg

Member
Licensed User
Longtime User
A really basic question. I have a spinner but can't get it to load items.

What is the "Event" in Spinner.Initialize(Event As String)?

B4X:
Sub Globals
   Dim Spinner1 As Spinner
End Sub
Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then

    End If
    Activity.LoadLayout("Location")   
    Spinner1.Initialize("InitializeSpinner1") '<<<< Is this correct?
    Spinner1.Add("Item1")
    Spinner1.Add("Item2")
    Spinner1.Add("Item3")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)   
End Sub
Sub Spinner1_ItemClick (Position As Int, Value As Object)
End Sub
Sub InitializeSpinner1
End Sub

Any assistance greatly apprecaited.:sign0104:
 

cymorg

Member
Licensed User
Longtime User
Not resolved

This resolved the problem
B4X:
    If FirstTime Then
           Spinner1.Initialize("InitializeSpinner1")
    End If
    Activity.LoadLayout("Location")    
    Spinner1.Add("Item1")
    Spinner1.Add("Item2")
    Spinner1.Add("Item3")

I'm still not sure what the purpose of InitializeSpinner1 event is for.
 
Last edited:
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
One thing is if you added the spinner in the designer then you don't need to initialize it

Sent from my DROIDX
 
Upvote 0

splatt

Active Member
Licensed User
Longtime User
you can also use:

B4X:
spnTimeSlot.AddAll(Array As String("AM","PM","All Day"))
 
Upvote 0

bluejay

Active Member
Licensed User
Longtime User
Replace

B4X:
Sub Spinner1_ItemClick (Position As Int, Value As Object)
End Sub
Sub InitializeSpinner1
End Sub

with
B4X:
Sub InitializeSpinner1_ItemClick (Position As Int, Value As Object)
End Sub

"InitializeSpinner1" is the prefix of the names of the subroutines that will handle this objects events. For a spinner object there is only one event "ItemClick" so when an item in the spinner is clicked B4A goes looking for a sub called "InitializeSpinner1_ItemClick".

It you are not interested in getting this event, which for a spinner is not uncommon, you can just use, Spinner1.Initialize("")

Bluejay
 
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
This resolved the problem
B4X:
    If FirstTime Then
           Spinner1.Initialize("InitializeSpinner1")
    End If
    Activity.LoadLayout("Location")    
    Spinner1.Add("Item1")
    Spinner1.Add("Item2")
    Spinner1.Add("Item3")

I'm still not sure what the purpose of InitializeSpinner1 event is for.

Since you haven't mentioned getting an error on the Initialize line, I assume that you are not loading a Designer layout with the spinner in it.

Anyway, if you Initialize the spinner only the FirstTime, then you will get an error if Android restarts your app, such as when you rotate the device.

Also, the Event name InitializeSpinner1 seems confusing since it seems unlikely that you are using the spinner's Click event to initialize anything, much less Spinner1. Normally you would just say:

Spinner1.Initialize("Spinner1")

Then the Click Event sub will be Sub Spinner1_Click(...) instead of Sub InitializeSpinner1_Click(...).

But say that you had multiple Spinners and you wanted them all to use the same Click event, then you would initialize them all with the same event name, such as Spin1.Initialize("Spin"), Spin2.Initialize("Spin"), etc.

In case you are saying that you don't know what the Spinner's Click event is for --

The Spinner is like a Label with a drop-down list. You can click on an item in the list to select it and the Click event tells you which item you clicked.
 
Last edited:
Upvote 0
Top