Android Question Timer and Listview

apty

Active Member
Licensed User
Longtime User
I have a some items in a list that i load in to a listview. I will like to load 2 items after every 1 second until i load all the items i.e. i have 20 items. Please help on how to achieve this.
 

DonManfred

Expert
Licensed User
Longtime User
What did you try so far?
show us your code you tried...

What are your thoughts on "how it should maybe work"?

What did YOU do to archieve your request? i mean instead of just asking here for a code for you but doing no self work for this
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private lv As ListView
    Private queue As List
    Private tmr As Timer
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    ' Clear listview
    lv.Clear
   
    ' Initialze the queue (items to add them - timerbased - to the listview
    queue.Initialize
   
    ' creating 100 dummy items and adding them to the queue
    For i = 1 To 100
        Dim m As Map
        m.Initialize
        m.Put("Line1","Bla bla bla "&i)
        m.Put("Line2","ho ho ho #"&i)
        m.Put("Another string or whatever","Test")
        queue.Add(m)
    Next
   
    ' initialize the time which will add items from the queue to the lv
    tmr.Initialize("QueueTimer",1000)
End Sub
Sub Activity_Resume
    ' start the timer
    tmr.Enabled = True
End Sub
Sub Activity_Pause (UserClosed As Boolean)
    ' Stop timer when paused
    tmr.Enabled = False
End Sub
Sub QueueTimer_Tick
    If queue.Size > 0 Then
        ' The queue is not empty
       
        ' get the first item to add
        Dim m As Map = queue.Get(0)   
        lv.AddTwoLines2(m.Get("Line1"),m.Get("Line2"),m)
       
        ' now we remove the first item from the queue cause we just have added it to the LV
        queue.RemoveAt(0)
        If queue.Size > 0 Then
            ' The queue is still not empty
           
            ' get another item to add
            Dim m As Map = queue.Get(0)   
            lv.AddTwoLines2(m.Get("Line1"),m.Get("Line2"),m)
           
            ' now we remove the "new" first item from the queue cause we just have added it to the LV
            queue.RemoveAt(0)
            Log("items in QUEUE: "&queue.Size)
        End If
    End If
End Sub
Sub lv_ItemClick (Position As Int, Value As Object)
    Dim m As Map = Value
    Log("Clicked item no "&Position)
    Log("Line1: "&m.Get("Line1"))
    Log("Line2: "&m.Get("Line2"))
   
End Sub
 
Upvote 0
Top