Android Question How can i use customlistview for lazy load to display this record

Makumbi

Well-Known Member
Licensed User
Please help me out how can i use custom list view to display this json record well it is a breakdown of Results obtained in End term 1 , End term 2 etc please help me iam desperately in need of having this display using customlivist views so

B4X:
[{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"DIVISION","Mid":null,"Ends":null,"Grade":null,"Term":"END TERM 1 2019","Years":"2019","Class":"P1","Total":2,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"DIVISION","Mid":null,"Ends":null,"Grade":null,"Term":"END TERM 2 2019","Years":"2019","Class":"P1","Total":2,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"DIVISION","Mid":null,"Ends":null,"Grade":null,"Term":"MID TERM 1 2019","Years":"2019","Class":"P1","Total":2,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"DIVISION","Mid":null,"Ends":null,"Grade":null,"Term":"MID TERM2 2019","Years":"2019","Class":"P1","Total":2,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"DIVISION","Mid":null,"Ends":null,"Grade":null,"Term":"MID TERM3 2019","Years":"2019","Class":"P1","Total":2,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"ENGLISH","Mid":null,"Ends":null,"Grade":"3","Term":"END TERM 1 2019","Years":"2019","Class":"P1","Total":70,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"ENGLISH","Mid":null,"Ends":null,"Grade":"3","Term":"MID TERM 1 2019","Years":"2019","Class":"P1","Total":75,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"ENGLISH","Mid":null,"Ends":null,"Grade":"6","Term":"MID TERM2 2019","Years":"2019","Class":"P1","Total":55,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"ENGLISH","Mid":null,"Ends":null,"Grade":"7","Term":"END TERM 2 2019","Years":"2019","Class":"P1","Total":52,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"ENGLISH","Mid":null,"Ends":null,"Grade":"7","Term":"MID TERM3 2019","Years":"2019","Class":"P1","Total":52,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"LITERACY1","Mid":null,"Ends":null,"Grade":"3","Term":"END TERM 1 2019","Years":"2019","Class":"P1","Total":70,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"LITERACY1","Mid":null,"Ends":null,"Grade":"3","Term":"MID TERM2 2019","Years":"2019","Class":"P1","Total":75,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"LITERACY1","Mid":null,"Ends":null,"Grade":"4","Term":"MID TERM3 2019","Years":"2019","Class":"P1","Total":67,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"LITERACY1","Mid":null,"Ends":null,"Grade":"5","Term":"MID TERM 1 2019","Years":"2019","Class":"P1","Total":64,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"LITERACY1","Mid":null,"Ends":null,"Grade":"6","Term":"END TERM 2 2019","Years":"2019","Class":"P1","Total":59,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"LITERACY2","Mid":null,"Ends":null,"Grade":"3","Term":"MID TERM2 2019","Years":"2019","Class":"P1","Total":71,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"LITERACY2","Mid":null,"Ends":null,"Grade":"4","Term":"END TERM 1 2019","Years":"2019","Class":"P1","Total":68,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"LITERACY2","Mid":null,"Ends":null,"Grade":"5","Term":"END TERM 2 2019","Years":"2019","Class":"P1","Total":61,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"LITERACY2","Mid":null,"Ends":null,"Grade":"5","Term":"MID TERM 1 2019","Years":"2019","Class":"P1","Total":63,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"LITERACY2","Mid":null,"Ends":null,"Grade":"6","Term":"MID TERM3 2019","Years":"2019","Class":"P1","Total":56,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"MATHEMATICS","Mid":null,"Ends":null,"Grade":"2","Term":"MID TERM3 2019","Years":"2019","Class":"P1","Total":80,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"MATHEMATICS","Mid":null,"Ends":null,"Grade":"3","Term":"MID TERM2 2019","Years":"2019","Class":"P1","Total":71,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"MATHEMATICS","Mid":null,"Ends":null,"Grade":"3","Term":"END TERM 2 2019","Years":"2019","Class":"P1","Total":76,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"MATHEMATICS","Mid":null,"Ends":null,"Grade":"5","Term":"END TERM 1 2019","Years":"2019","Class":"P1","Total":60,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"MATHEMATICS","Mid":null,"Ends":null,"Grade":"8","Term":"MID TERM 1 2019","Years":"2019","Class":"P1","Total":49,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"R.E","Mid":null,"Ends":null,"Grade":"5","Term":"MID TERM3 2019","Years":"2019","Class":"P1","Total":61,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"TOTAL AGG","Mid":null,"Ends":null,"Grade":null,"Term":"END TERM 2 2019","Years":"2019","Class":"P1","Total":0,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"TOTAL AGG","Mid":null,"Ends":null,"Grade":null,"Term":"MID TERM3 2019","Years":"2019","Class":"P1","Total":0,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"TOTAL AGG","Mid":null,"Ends":null,"Grade":null,"Term":"END TERM 1 2019","Years":"2019","Class":"P1","Total":15,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"TOTAL AGG","Mid":null,"Ends":null,"Grade":null,"Term":"MID TERM2 2019","Years":"2019","Class":"P1","Total":15,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"TOTAL AGG","Mid":null,"Ends":null,"Grade":null,"Term":"MID TERM3 2019","Years":"2019","Class":"P1","Total":19,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"TOTAL AGG","Mid":null,"Ends":null,"Grade":null,"Term":"END TERM 2 2019","Years":"2019","Class":"P1","Total":21,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"TOTAL AGG","Mid":null,"Ends":null,"Grade":null,"Term":"MID TERM 1 2019","Years":"2019","Class":"P1","Total":21,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"TOTAL MARKS","Mid":null,"Ends":null,"Grade":null,"Term":"END TERM 2 2019","Years":"2019","Class":"P1","Total":0,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"TOTAL MARKS","Mid":null,"Ends":null,"Grade":null,"Term":"MID TERM3 2019","Years":"2019","Class":"P1","Total":0,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"TOTAL MARKS","Mid":null,"Ends":null,"Grade":null,"Term":"END TERM 2 2019","Years":"2019","Class":"P1","Total":248,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"TOTAL MARKS","Mid":null,"Ends":null,"Grade":null,"Term":"MID TERM 1 2019","Years":"2019","Class":"P1","Total":251,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"TOTAL MARKS","Mid":null,"Ends":null,"Grade":null,"Term":"MID TERM3 2019","Years":"2019","Class":"P1","Total":255,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"TOTAL MARKS","Mid":null,"Ends":null,"Grade":null,"Term":"END TERM 1 2019","Years":"2019","Class":"P1","Total":268,"atk":"0"},{"Account":"19-07561","Names":"MAKUMBI TARIQ AZIZI","Stream":"F","Subject":"TOTAL MARKS","Mid":null,"Ends":null,"Grade":null,"Term":"MID TERM2 2019","Years":"2019","Class":"P1","Total":272,"atk":"0"}]

B4X:
Dim jt As HttpJob
    jt.Initialize("", Me)
    jt.Download("http://kccug.com/KabojjaApp/HandlerVBArchive.ashx")
    'jt.GetRequest.Timeout =2000 '10 seconds
    
    'Sleep(0)
    Wait For (jt) JobDone(jt As HttpJob)
    If jt.Success Then ' if job is success (http status code 200)
    Dim RetVal As String
    RetVal = jt.GetString
    Log(RetVal)
    If jt.GetString = "[]" Then
        'MsgboxAsync("No Records to Upload Yet for: " & CustID ,"SMIS")
        Return
    Else
            
        Dim jp As JSONParser
        jp.Initialize(jt.GetString)
        'Log(jp) ' will pr
        Log($"Token(${jp})"$)
        Dim quotdt As List = jp.NextArray
        For Each quotd As Map In quotdt
            Log("Account: " & quotd.Get("Account"))
            Log("Grade: " & quotd.Get("Grade"))
            Log("Mids: " & quotd.Get("Mid"))
            Log("Ends: " & quotd.Get("Ends"))
            Log("Stream: " & quotd.Get("Stream"))
            Log("Names: " & quotd.Get("Names"))
            Log("Class: " & quotd.Get("class"))
            Log("Term: " & quotd.Get("Term"))
            Log("Subject: " & quotd.Get("Subject"))
            Log("Total: " & quotd.Get("Total"))
            Log("atk: " & quotd.Get("autofield"))

                        
                'Starter.SQL1.ExecNonQuery("INSERT INTO Academics VALUES('" & quotd.Get("Names") & "','" & quotd.Get("class") & "','" & quotd.Get("Stream") & "','" & quotd.Get("Subject")  & "','" & quotd.Get("Total") & "','" & quotd.Get("Grade") & "','" & quotd.Get("Mid")  & "','" & quotd.Get("Ends") & "','" & quotd.Get("Term") & "','" & quotd.Get("Years") & "','" & quotd.Get("atk") & "')")
                                Starter.SQL1.ExecNonQuery2("INSERT INTO Academicspast VALUES(?, ?, ?,?, ?, ?,?, ?,?,?,?)", Array As Object(quotd.Get("Names"), quotd.Get("Class"), quotd.Get("Stream"),quotd.Get("Subject"),quotd.Get("Total") ,quotd.Get("Grade"),quotd.Get("Mid"),quotd.Get("Ends"),quotd.Get("Term"),quotd.Get("Years"),quotd.Get("atk")))
        Next
            

        'Return
            ProgressDialogShow2("Processing the Final data...",False)
            Sleep(100)
        ProgressDialogHide
            'StartActivity(Archiveprimary)
    End If
        
    End If
    
    jt.Release


B4X:
below is what i was trying to do in that snapt shot but i wanted the marks to come out when grouped by term 


Sub ShowPastrecords_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    Dim ExtraSize As Int = 25 'List size
    For i = Max(0, FirstIndex - ExtraSize) To Min(LastIndex + ExtraSize, showpastrecords.Size - 1)
        Dim Pnl As B4XView = showpastrecords.GetPanel(i)
        If i > FirstIndex - ExtraSize And i < LastIndex + ExtraSize Then
            If Pnl.NumberOfViews = 0 Then 'Add each item/layout to the list/main layout
                Dim AD As StudentData = showpastrecords.GetValue(i)
                Pnl.LoadLayout("Studentpastinfo")
            '    Studentnamed.Text = AD.Studentnamed
                'label2.Text= AD.Studentnamed
                'Log(Studentnamed.Text)
                Classr.Text = AD.Classr
                Stream.Text = AD.Stream
                label2.Text = AD.Termr
                Label9.Text= AD.Subject
                'LblICAO.Text = AD.ICAO
                LblCity.Text = AD.Studentnamed
                 Totalmarks.Text = AD.Totalmarks
                'LblLongitude.Text = AD.Longitude
                'LblAltitude.Text = AD.Altitude
            End If
        Else 'Not visible
            If Pnl.NumberOfViews > 0 Then
                Pnl.RemoveAllViews 'Remove none visable item/layouts from the list/main layout
            End If
        End If
    Next
End Sub

Sub TxtSearchFilter_TextChanged (Old As String, New As String)
    If New.Length = 1 Or TxtSearchFilter.Text.Length = 2 Then Return
    showpastrecords.Clear
    Sleep(0)

    Dim SenderFilter As Object
    If New.Length = 0  Then
    StudentCount = Starter.SQL1.ExecQuerySingleResult("SELECT COUNT(*) FROM `academicspast`;") 'The amuont of airports listed in the database
        SenderFilter = Starter.sql1.ExecQueryAsync("SQL", $"SELECT * FROM `academicspast` ORDER BY `Names` ASC LIMIT ${Limit};"$, Null) 'I NO NOT RECOMMEND that you load the whole database
    Else
        StudentCount = 0
        SenderFilter = Starter.sql1.ExecQueryAsync("SQL", $"SELECT * FROM `academicspast` WHERE `Names` Like '%${New}%' ORDER BY `Name` ASC LIMIT 500;"$, Null) 'Limited for slower devices
    End If

    Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, rs As ResultSet)
    If Success Then
        Dim StartTime As Long = DateTime.Now
        Do While rs.NextRow
            Dim AD As StudentData
            AD.Initialize
            AD.Studentnamed    = rs.GetString("Names")
            AD.Classr = rs.GetString("Class")
            AD.Stream    = rs.GetString("Stream")
            AD.Termr = rs.GetString("Term")
            AD.Subject= rs.GetString("Subject")
            AD.Totalmarks= rs.GetString("Total")
        '    AD.ICAO    = rs.GetString("ICAO")
        '    AD.City    = rs.GetString("City")
        '    AD.Latitude    = rs.GetString("Latitude")
        '    AD.Longitude = rs.GetString("Longitude")
        '    AD.Altitude    = $"${rs.GetString("Altitude in feet")} ft"$
                
            Dim Pnl As B4XView = XUI.CreatePanel("")
            Pnl.SetLayoutAnimated(0, 0, 0, showpastrecords.AsView.Width, 130dip) 'Panel height + 4 for drop shadow
            showpastrecords.Add(Pnl, AD)
        Loop
        rs.Close
        
        Log($"List population time = ${NumberFormat2((DateTime.Now - StartTime) / 1000, 1, 2, 2, False)} seconds to populate ${showpastrecords.Size} airport names"$)
    Else
        Log(LastException)
    End If
    
    'Add an icon to the activity text by using CSBuilder
    If StudentCount = 0 Then
        Activity.Title = CS.Initialize.Typeface(Typeface.FONTAWESOME).Append(Chr(0xF072)).Append($" ${showpastrecords.Size} Airports"$).PopAll
    Else
        Activity.Title = CS.Initialize.Typeface(Typeface.FONTAWESOME).Append(Chr(0xF072)).Append($" Loaded ${Limit} airports from ${StudentCount}"$).PopAll
    End If
End Sub
 

Attachments

  • Screenshot_1582055252.png
    Screenshot_1582055252.png
    102.6 KB · Views: 174
Top