Android Question Spinner does not display selectedItem in it.

StephenRM

Member
A Spinner is loaded based on the condition, this Spinner shows the values loaded in it correctly and when selected from the dropdown, the Position and Value also work.
But in the Spinner the SelectedItem is not seen, it remains blank.
 

StephenRM

Member
Spinner is blank:
Try
        Dim pnl As B4XView = xui.CreatePanel("")
        Dim  lbl As Label
        
        wv.Initialize("")
        lbl.Initialize("")
        chkSngl_Dbl.Initialize("chkSngl_Dbl")
        spnB.Initialize("spnB")
        spnB.TextColor = Colors.White
        spnC.Initialize("spnC")
        spnC.TextColor = Colors.White
        spnV.Initialize("spnV")
        spnV.TextColor = Colors.White
        SQL_Util.LoadSpinner("SELECT * FROM Books  WHERE  BookID>=1 AND BookID<=66", spnB, Starter.SQL_Books,1)    'Works properly, no issues here

Spinner is blank:
Sub spnB_ItemClick (Position As Int, Value As Object)
    spnC.Enabled = True
    BkID = Starter.SQL_Books.ExecQuerySingleResult("SELECT BookID FROM Books WHERE BookName LIKE '" & Value & "' ")
    
    A = Starter.SQL_Books.ExecQuerySingleResult("SELECT Bk_Acro FROM Books WHERE BookName LIKE '" & Value & "' ")
    
    Dim limit As Int = 50
    spnC.Clear
     'Load the Spinner with values
     For i=1 To limit
        spnC.Add(i)   
    Next
    spnC.SelectedIndex = 0

The above Spinner spnC is loaded with values 1 to 50, after selection, Spinner display is blank.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
The problem is that you are trying to populate the Spinner by his ItemClick Event.
Initially the Spinner is without any items.............. so there is nothing to Click and the ItemClick Event will never be raised.
You need to populate the Spinner somewhere else in your code (for example after loading the Layout) and then you will be able to do everything.
Example
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    
    For x = 0 To 49
        Spinner1.Add(x)
    Next
    Spinner1.SelectedIndex = 0
    
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub Spinner1_ItemClick (Position As Int, Value As Object)
    'Do what you need with the selected item here................
End Sub
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I didn't noticed that you was referring to 2 different spinners.
I post here an example that should basically do what you was trying to do.
 

Attachments

  • Two_Spinners.zip
    14.1 KB · Views: 179
Upvote 0
Top