Android Question event dont trigger?

EddyW

Member
Licensed User
We made a application that get data from a webservice on 1 acitivity we have a tabhost with several tabs.
On 1 of the tabs we generate the edittext and spinnners based on what we get from the webservice.
All did work well but suddenly the Sub svSpinner_ItemClick wont trigger anymore.
B4X:
Sub VulMateriaalLijst(intGroep As Int)
    Dim Table As List
    Dim Record() As String
    Dim intAantalRegels As Int

    svMateriaal.Panel.RemoveAllViews

    If DB.InitialiseerSQL Then
        LogColor(currentOpdracht.opdrachtTypeID, Colors.Blue)
        Select intGroep
        Case 1
            Table = DBUtils.ExecuteMemoryTable(DB.SqlDB, "select *  from Materiaal where OpdrachtTypeID = ? and upper(MateriaalGroep) like '%ARBEID%' ", Array As String(currentOpdracht.opdrachtTypeID),0)
        Case 2
            BTN_Materiaal.TextColor = Colors.Green
            Table = DBUtils.ExecuteMemoryTable(DB.SqlDB, "select * from Materiaal where OpdrachtTypeID = ? and upper(MateriaalGroep) like '%MATERIAAL%' ", Array As String(currentOpdracht.opdrachtTypeID),0)
        Case 3
            BTN_Uren.TextColor = Colors.Green
            Table = DBUtils.ExecuteMemoryTable(DB.SqlDB, "select * from Materiaal where OpdrachtTypeID = ? and upper(MateriaalGroep) like '%UREN%' ", Array As String(currentOpdracht.opdrachtTypeID),0)
        Case 4
            BTN_Meerwerk.TextColor = Colors.Green
            Table = DBUtils.ExecuteMemoryTable(DB.SqlDB, "select * from Materiaal where OpdrachtTypeID = ? and upper(MateriaalGroep) like '%MEERWERK%' ", Array As String(currentOpdracht.opdrachtTypeID),0)
        Case 5
            BTN_Staatwerk.TextColor = Colors.Green
            Table = DBUtils.ExecuteMemoryTable(DB.SqlDB, "select *  from Materiaal where OpdrachtTypeID = ? and upper(MateriaalGroep) like '%STRAATWERK%' ", Array As String(currentOpdracht.opdrachtTypeID),0)
        End Select
    End If

    If Table.IsInitialized Then
        intAantalRegels = Table.Size - 1
        For i = 0 To Table.Size - 1
            Record = Table.get(i)

            ' splitsen Record
            Dim sExternID As String = Record(0)
            Dim sMateriaalCode As String = Record(1)
            Dim sMateriaalOmschrijving As String = Record(2)
            Dim sMateriaalVeldType As String = Record(3)
            Dim sMateriaalKeuzelijst As String = Record(4)
            Dim sVerplicht As String = Record(5)
            sMateriaalVeldType = sMateriaalVeldType.Trim.ToUpperCase
            sMateriaalKeuzelijst= sMateriaalKeuzelijst.Replace(" ", "")

            If sVerplicht = "1" Then
                sMateriaalOmschrijving = sMateriaalOmschrijving & " (Verplicht)"
            End If

            ' Materiaallijst opbouw
            Dim svPanel As Panel
            Dim svMateriaalCode As Label
            Dim svMateriaalOmschrijving As Label
            Dim svMateriaalVoorCalc As Label
            Dim svEditText As EditText
            Dim svSpinner As Spinner

            svPanel.Initialize("svPanel")
            svMateriaal.Panel.AddView(svPanel, 0, 3dip+i*PanelHeight,100%x, PanelHeight)

            svMateriaalCode.Initialize("svMateriaalCode")
            svPanel.AddView(svMateriaalCode, 4%x, 3dip, 10%x, 40dip)
            svMateriaalCode.Tag = sExternID
            svMateriaalCode.TextSize = 20
            svMateriaalCode.Text = sMateriaalCode

            svMateriaalOmschrijving.Initialize("svMateriaalOmschrijving")
            svPanel.AddView(svMateriaalOmschrijving, 15%x, 3dip, 50%x, 40dip)
            svMateriaalOmschrijving.Tag = sExternID
            svMateriaalOmschrijving.TextSize = 20
            svMateriaalOmschrijving.Text = sMateriaalOmschrijving

            svMateriaalVoorCalc.Initialize("svMateriaalVoorCalc")
            svPanel.AddView(svMateriaalVoorCalc, 65%x, 3dip, 15%x, 40dip)
            svMateriaalVoorCalc.Tag = sExternID
            svMateriaalVoorCalc.TextSize = 20
            svMateriaalVoorCalc.Text = Lookup(sExternID, 1)
            svMateriaalVoorCalc.Gravity = Bit.OR(Gravity.LEFT, Gravity.CENTER_VERTICAL)

            Select Case sMateriaalVeldType
            Case "COMBO"
                svSpinner.Initialize("svSpinner")
                svSpinner.Add("")

                Dim lKeuzelijst As List
                lKeuzelijst.Initialize
                lKeuzelijst.AddAll(Regex.Split(";", sMateriaalKeuzelijst))
                svSpinner.AddAll(lKeuzelijst)
                svSpinner.Tag = sExternID
                svPanel.AddView(svSpinner, 76%x, 3dip, 15%x, 40dip)
                LogColor(sExternID, Colors.Red)
                If Lookup(sExternID, 2) <> "" Then
                    Dim sLookup As String = Lookup(sExternID, 2)
                    svSpinner.SelectedIndex = svSpinner.IndexOf(sLookup)
                End If
            Case Else
                svEditText.Initialize("svEditText")
                svEditText.SingleLine = True
'                svEditText.ForceDoneButton = True
                svPanel.AddView(svEditText, 76%x, 3dip, 15%x, 40dip)
                svEditText.Tag = sExternID
                svEditText.Text = Lookup(sExternID, 2)
            End Select

        Next
    End If
    svMateriaal.Panel.Height = 150dip + (intAantalRegels * PanelHeight)
End Sub

Sub svSpinner_ItemClick(Position As Int, Value As Object)
    LogColor(Value, Colors.Red)
    Dim keuze As Spinner
    keuze = Sender
    If keuze.SelectedItem.Trim.Length <>0 Then ToevoegenRegel(keuze.Tag, keuze.SelectedItem)
End Sub

Sub svEditText_EnterPressed
    Dim text As EditText
    text = Sender
    If text.text.Trim.Length <>0 Then ToevoegenRegel(text.Tag, text.text)
End Sub

Sub svEditText_FocusChanged (HasFocus As Boolean)
    Dim text As EditText
    text = Sender
    If HasFocus = False AND text.text <> "" Then
        If text.text.Trim.Length <>0 Then ToevoegenRegel(text.Tag, text.text)
    End If
End Sub

Sub ToevoegenRegel(sExternID As String, sWaarde As String)
    Dim listOfMaps As List
    Dim WhereFields, mResultDB As Map
    Dim sDatum As String

    DateTime.DateFormat = "yyyyMMdd"
    sDatum = DateTime.Date(DateTime.Now)

    If DB.InitialiseerSQL Then
        mResultDB = DBUtils.ExecuteMap(DB.SqlDB, "SELECT * FROM OpdrachtMateriaal WHERE OpdrachtID = ? and ExternID = ?", Array As String(currentOpdracht.opdrachtid, sExternID))
        If mResultDB.IsInitialized Then
            ' Update
            WhereFields.Initialize
            WhereFields.Put("OpdrachtID", currentOpdracht.opdrachtid)
            WhereFields.Put("ExternID", sExternID)

            DBUtils.UpdateRecord(DB.SqlDB, "OpdrachtMateriaal", "NaCalc", sWaarde, WhereFields)
            DBUtils.UpdateRecord(DB.SqlDB, "OpdrachtMateriaal", "Datum",sDatum , WhereFields)
            DBUtils.UpdateRecord(DB.SqlDB, "OpdrachtMateriaal", "Upload", 1, WhereFields)

        Else
            'Insert
            Dim m As Map
            m.Initialize
            m.Put("OpdrachtID", currentOpdracht.opdrachtid)
            m.Put("Monteur", Main.monteur)
            m.Put("ExternID", sExternID)
            m.Put("NaCalc", sWaarde)
            m.Put("Datum", sDatum)
            m.Put("Upload", 1)

            listOfMaps.Initialize
            listOfMaps.Add(m)
            DBUtils.InsertMaps(DB.SqlDB, "OpdrachtMateriaal", listOfMaps)
        End If
    End If

End Sub

Sub Lookup(sExternID As String, iType As Int) As String
    Dim sWaarde As String
    Dim mResultDB As Map

    If DB.InitialiseerSQL Then
        mResultDB = DBUtils.ExecuteMap(DB.SqlDB, "SELECT * FROM OpdrachtMateriaal WHERE OpdrachtID = ? and ExternID = ?", Array As String(currentOpdracht.opdrachtid, sExternID))
        If mResultDB.IsInitialized Then
            If iType = 1 Then
                sWaarde = mResultDB.get("voorcalc")
            Else
                sWaarde = mResultDB.get("nacalc")
            End If
        Else
            sWaarde = ""
        End If
    End If
    Return sWaarde.Trim
End Sub

The code that generate the edittext & spinners i will post but thats not all the code of the app/activity
Cant upload the project because its for a customer.

does anyone know why the svSpinner_ItemClick dont trigger when you select a item in the spinner?
The code for the svEditText doe work and the svEditText_EnterPressed event does trigger.

svSpinner is unique name within this project
 
Last edited:

EddyW

Member
Licensed User
We tested it and didnt found why it happens but noticed that when we disable or change order of some other panels/tabs it works again.
Weird enough the other panel/tabs we disabled hadnt any spinners (most panels have only labels and edittext fields)

But we solved it to loop thru all views with GetAllViewsRecursive to get the the Tag and the selecteditem to update the recordset.
 
Upvote 0

mc73

Well-Known Member
Licensed User
If for eg another panel has lower z-order perhaps its touch event consumes clicking upon the spinner.
 
Upvote 0

EddyW

Member
Licensed User
maybe but would be weird because the edittext's that are above and below the spinner does work.
How do you set the Z order when you have a tabhost with several tabs and each tab has 1 or more panels?
 
Upvote 0
Top