Android Question Countdown timer in CustomListView

Gktech

Member
Licensed User
Move this code to a class and pass a Label in the Initialize method. Update the label from the class.

Create a class instance for each of the items in the list.

@Erel do you have a sample code?
Error is a part of my code:
B4X:
For Each link As String In links
Dim p As Panel
            p.Initialize("")
            clv.Add(p, 50%y, link)
      
            p.LoadLayout("exibi_lista_carros")
            lblValor.Text = "Text" '<----- (countdown timer)

Next
 
Upvote 0

Gktech

Member
Licensed User
I'm not getting any errors,
I have not yet found a method of updating multiple countdowns in a CustomListView
How can I do this?
 
Upvote 0

Gktech

Member
Licensed User
This is a part of my code:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Try
        'Do not forget to load the layout file created with the visual designer. For example:
        Activity.LoadLayout("lista_carros")
        SQL1.Initialize(File.DirDefaultExternal, "ijavendi.db", True)
        'StartService(Starter)
   
        timer_online.Initialize("timer_online", 60000)
        timer_online.Enabled = True
   
        clv.Initialize(Me, "clv")
        Activity.AddView(clv.AsView, 0, 12%y, 100%x, 88%y)
   
        PopupMenu.Initialize("PopupMenu",imgMenu)
        PopupMenu.AddMenuItem(0, 0, "Preferencia")
        PopupMenu.AddMenuItem(2, 1, "Vender Carro")
        PopupMenu.AddMenuItem(3, 2, "Estoque de Carros")
        PopupMenu.AddMenuItem(1, 3, "Sair")
        StartService(Starter)
       
    Catch
        gravaLog(LastException.Message,"Activity_Create")
    End Try
   
End Sub

Sub recebeDados(dados As String)
    Try
        links.Initialize
        lista_carros.Initialize("lista_carros", Me)

        Log(servridor &"listaCarros.php?acao=1&id_user="& id_comprador)
        lista_carros.PostString(servridor &"listaCarros.php?acao=1", "id_user="& id_comprador)
        inicio = 1
    Catch
        gravaLog(LastException.Message,"recebeDados")
    End Try   
End Sub

Sub JobDone (Job As HttpJob)
    'Log("Nome = " & Job.JobName & ", Success = " & Job.Success)   
    'Dim Map1 As Map
    If Job.Success = True Then
        Select Job.JobName
            Case "lista_carros"
                Dim p As JSONParser
                Dim response As String
                response = Job.GetString
                p.Initialize(response)
               
                Dim rows As List
                rows = p.NextArray

                links.Clear
                If rows.Size <> 0 Then
                    For i = 0 To rows.Size - 1
                        links.Add(rows.Get(i))
                    Next
                    BuildItems
                Else
                    semCarros
                End If
        End Select
    Else
        Log(Job.ErrorMessage)
        gravaLog(LastException.Message,"Case lista_carros")
    End If
    ProgressDialogHide
End Sub

Sub BuildItems
    Try
        lblInfoCarros.Visible = False
        buscaIdComprador
        usuario_online.Initialize("usuario_online", Me)
        usuario_online.PostString(servridor &"usuario_online.php?acao=1", "id_comprador="& id_comprador)
   
        If links.Size = 0 Then Return
       
        clv.Clear
        Dim m As Map
        m.Initialize
        For Each link As String In links

            Dim p As Panel
            p.Initialize("painel_carro")
            clv.Add(p, 50%y, link)
           
            p.LoadLayout("exibi_lista_carros")       
           
            Dim components() As String
            components = Regex.Split("-", link)
            Log(servridor_imagem & components(6))
            m.Put(imgCarroLista, servridor_imagem & components(6))
               
            lblValor.Text = components(4)
            lblModelo.Text = components(1)
            'lblTempoRest.Text = ""       
        Next   
        CallSubDelayed2(ImageDownloader, "Download", m)
        ProgressDialogHide
    Catch
        gravaLog(LastException.Message,"BuildItems")
    End Try
   
End Sub

Sub StartTimer (Hours As Int, Minutes As Int, Segundos As Int)
    targetTime = DateTime.Now + Hours * DateTime.TicksPerHour + Minutes * DateTime.TicksPerMinute + Segundos * DateTime.TicksPerSecond
    timer1.Enabled = True
End Sub

Sub Timer1_Tick
    Dim t As Long = Max(0, targetTime - DateTime.Now)
    Dim  hours, minutes, seconds As Int
    hours = t / DateTime.TicksPerHour
    minutes = (t Mod DateTime.TicksPerHour) / DateTime.TicksPerMinute
    seconds = (t Mod DateTime.TicksPerMinute) / DateTime.TicksPerSecond
    Log($"$2.0{minutes}:$2.0{seconds}"$)
    lblTempoRest.Text = $"$2.0{hours}:$2.0{minutes}:$2.0{seconds}"$
    If t = 0 Then
        timer1.Enabled = False
    End If
   
End Sub
 
Upvote 0

Gktech

Member
Licensed User
i attached a Sample project.
See if it helps, achieve what are you trying to do.

painel.png

@XbNnX_507
The solution was what I was looking for but I have a sequence of panels inside one another how to find the label in GetView?
 
Upvote 0

Gktech

Member
Licensed User
Sorry, it was a misunderstanding.
But the question I asked is a ref question to the solution that the @XbNnX_507 left attached, which I have to adapt in my layout so the question.
 
Upvote 0

XbNnX_507

Active Member
Licensed User
Longtime User
painel.png

Assuming you have everything in the correct order...
B4X:
dim FirstPanel as paneL = Panel1
dim SecondPanel as paneL = FirstPanel.getview(0)
dim ThirdPanel as paneL = SecondPanel.getview(0)
dim lbl as label = ThirdPanel.getview(0)

Any further question, start a new thread.
 
Upvote 0
Top