Android Question CLV in XUI.CreatePanel appending data, not loading a new Panel

JonnyCav

Member
The code is below but the issue is simple to explain:
A layout loads the data (db search query) with an option (button) to change the date/period.
When the button is clicked, a variable changes and SHOULD reload the search query.

This all works perfectly well (I have 'Log' info that verifies this) BUT instead of a new, refreshed panel it just adds the new records.

I've tried all I can find such as pa.RemoveAll...etc. but whilst the record wasn't visible any longer, the panel kept getting longer.

Please someone point me in the right direction.

SCREEN:
Private Sub Load_Scores
    
    'INITALLY USING TODAY'S DATE AS DEFAULT
    
    
    Log(period)
    rs=Starter.sql.ExecQuery2 _
    ("SELECT studentId, studentName FROM Attendance WHERE groupName =? AND classPeriod=?" _
    ,Array As String(selectedGroup,period))
    
    
    Do While rs.NextRow
        
        Dim pa As B4XView = xui.CreatePanel("")
        
        pa.LoadLayout("ListOfStudentsScores")
        pa.SetLayoutAnimated(0,0,0,clvAttendance.AsView.Width,60dip)
        
            
        lblScores1.Text = rs.GetString("studentID")
        lblScores2.Text = rs.GetString("studentName")
        
        clvAttendance.Add(pa,"")
        
    
    Loop
    rs.Close
End Sub

WHEN THE RELOAD BUTTON IS PRESSED it loads this code (taking the new variable). This all works fine.

B4X:
Private Sub btnReloadScores_Click
    
    'IF A CHANGE IS MADE TO THE DEFAULT, THIS STORES THE (DATE) PERIOD AND THEN RELOADS
    'THE DATABASE SEARCH RESULTS
    
    period=txtClassPeriod.Text

    Load_Scores
End Sub
 

Mahares

Expert
Licensed User
Longtime User
Please someone point me in the right direction.

The reason you keep adding records to your xCLV is because you are not clearing the xCLV before each reload. You need to add :
B4X:
Private Sub btnReloadScores_Click
        clvAttendance.Clear    'add this line here
I think you get better and quicker help if you upload (attach) your project, not just code snippets, particularly when you have layouts. People cannot guess at what you have in those layouts and what your database structure and data are
To attach your project, in the IDE click 'File', then click 'Export as zip' since you are using a default type of project. If my answer does not solve it for you, you must export your project to the forum
 
Upvote 1
Top