Android Question spnAge.add do not add items. (Resolved)

Kjell

Member
Licensed User
Longtime User
First, It is working now, but I do not understand why, so please read.

I have a main activity and a tab host.
2 spinners on the Main activity (spnMeasures and spnSex) and one on the tab host (spnAge) (The one that is loaded by default when you start the app.

in activity create, I first loaded the Layout
then added tabs

then added items to the spinners:


B4X:
    spnMeasures.Add("Inches")
    spnMeasures.Add("Cm")
    spnSex.Add("Male")
    spnSex.Add("Female")
 
    spntAge.Add("")
    Dim i As Int
    For i = 0 To 100
        spnAge.Add(i)
    Next

When I ran the app, nothing was added to spnAge, but spnMeasures and spnSex was ok.
I moved spnAge from the tab layout to the layout for main.
Nothing added.
I deleted the members from main and re-created the member for spnAge from designer.
Nothing added
I deleted spnAge, deleted the member, duplicated spnSex, creted member for spnAge via the designer.
Nothing added
I deleted spnAge and the member, added New spinner and creted the member.
Nothing added.
I tried changing spnAge.Add(i) to spnAge.Add("HEY") and add spnAge.Add("DONE") after the loop.
Nothing added
B4X:
    spnMeasures.Add("Inches")
    spnMeasures.Add("Cm")
    spnSex.Add("Male")
    spnSex.Add("Female")
 
    spnCurrentAge.Add("")
    Dim i As Int
    For i = 0 To 100
        spnCurrentAge.Add("HEY")
    Next
spnAge.Add("DONE")

I changed the name from spnAge to spnCurrentAge
Deleted the spnAge member end re-created it in the designer.

B4X:
    spnMeasures.Add("Inches")
    spnMeasures.Add("Cm")
    spnSex.Add("Male")
    spnSex.Add("Female")
 
  
    Dim i As Int
    For i = 0 To 100
        spnCurrentAge.Add(i)
    Next

It works!!!

but.... why?
Do anyone have an idea?
 

DonManfred

Expert
Licensed User
Longtime User
Without seeing the complete code it´s hard to say what´s going wrong...
 
Upvote 0

Kjell

Member
Licensed User
Longtime User
its not much more code:
Calculation class:

B4X:
Public Sub Covert_Bailey(Gender As String, Age As Int, Hips As Int, Tigh As Int, Calf As Int, Wrist As Int) As Int

    If Gender = "Female" Then
        If Age = 30 OR Age < 30 Then
            Return(Hips +0.8 * Tigh - 2 * Calf - Wrist) '(For Women 30 years old OR younger)
        Else
            Return(Hips + Tigh - 2*Calf - Wrist) '(For Women over age 30)
        End If
    Else
        If Age > 30 Then
            Return(Tigh + 0.5 * Hips - 3 * Calf - Wrist) '(For Men 30 years old OR younger)
        Else
            Return(Tigh + 0.5* Hips - 2.7 * Calf - Wrist) '(For Men over age 30)
        End If
    End If

End Sub
Main activity:

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim calc As calculations
    calc.Initialize

    Private tbMain As TabHost
    Private edtCalf As EditText
    Private edtHips As EditText
    Private edtThigh As EditText
    Private edtWrist As EditText
    Private spnMeasures As Spinner
    Private spnSex As Spinner
    Private lblResult As Label

    Private spnAge As Spinner
End Sub

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
    tbMain.AddTab("Covert Bailey", "bailey")
    tbMain.AddTab("US Navy", "navy")
    tbMain.AddTab("BMI", "bmi")

    spnMeasures.Add("Inches")
    spnMeasures.Add("Cm")
    spnSex.Add("Male")
    spnSex.Add("Female")

    Dim i As Int
    For i = 0 To 100
        spnAge.Add(i)
    Next

End Sub

B4X:
Sub edtHips_TextChanged (Old As String, New As String)

    ToastMessageShow("edtHips fired", True)

        If IsNumber(edtHips.Text) AND IsNumber(edtThigh.Text) AND  IsNumber(edtCalf.Text) AND IsNumber(edtWrist.Text) Then
            lblResult.Text = calc.Covert_Bailey(spnSex.SelectedItem, spnAge.SelectedItem, edtHips.Text, edtThigh.Text, edtCalf.Text, edtWrist.Text)
        End If

End Sub
 
Last edited:
Upvote 0

Kjell

Member
Licensed User
Longtime User
I figured it out....
Kind of feel stupid now :oops:

I have spnAge in one of the layouts to another tab to (no coding done to work on other tabs yet, just layout), I was not thinking about these getting loaded at Activity_create before you push the tab.....
 
Upvote 0
Top