Android Question Unable to clear a listview

Serge Bertet

Active Member
Licensed User
hi,

do I need to loop over all items to clear an whole listview?
it looks like only the selected item is cleared with the clear method.
With
B4X:
PlayListView.Clear
or
B4X:
    Do While PlayListView.Size > 0
        PlayListView.RemoveAt(0)
    Loop
I always have new text over old text in some cells.
So looking for a way clear and refresh (refill) a listview with new values.

Thx
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
Clear should remove all items from the list. Can you post all the related code?

- Colin.
 
Upvote 0

Serge Bertet

Active Member
Licensed User
Here is the code used to refresh the listview:
B4X:
Sub ShowList
    PlayListView.Clear
    csr = Starter.db.ExecQuery("SELECT * FROM 'playlists' ORDER BY `playlistname` ASC")
    If csr.RowCount > 0 Then
        For i = 0 To csr.RowCount-1
            csr.Position = i
            PlayListView.AddSingleLine2(csr.GetString("playlistname"), csr.GetInt("ID"))
        Next
    End If
    ActionPanel.visible = False
End Sub
Hope that helps to help me.

Serge
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Here is the code used to refresh the listview:
B4X:
Sub ShowList
    PlayListView.Clear
    csr = Starter.db.ExecQuery("SELECT * FROM 'playlists' ORDER BY `playlistname` ASC")
    If csr.RowCount > 0 Then
        For i = 0 To csr.RowCount-1
            csr.Position = i
            PlayListView.AddSingleLine2(csr.GetString("playlistname"), csr.GetInt("ID"))
        Next
    End If
    ActionPanel.visible = False
End Sub
Hope that helps to help me.

Serge
So what happens when you run this code? The if statement is redundant btw. If there are no records in the cursor, the for loop won't execute.

- Colin
 
Upvote 0

Serge Bertet

Active Member
Licensed User
Yes, you'r rigth, the If is not needed here, but it is waiting for an Else ....:)
When I execute this code I can see the old text overwritted with the new one and at the end both (old ans new) are visible.
When I run step by step using the debugger it looks like only le last selected item is erased.
Android version on my test tablet is 4.2.1
Also used:
B4X:
    Do While PlayListView.Size > 0
        PlayListView.RemoveAt(0)
    Loop
with no result.

Serge
 
Last edited:
Upvote 0

Serge Bertet

Active Member
Licensed User
As per LucaMs advice I switched to xCutomListView but there is stil a ListView in another activity.
Yes I never close the cursor, maybe the problem is here, thx Mahares, i'll try.
.. and try with a delay ... I can see my tablet slowing down debug after debug until I restart.
For now I'm stuck with syntaxes containing $ I don't know what it is used for .... even "Beginners Guide" and "B4x Langage Basic" don't talk about that ... but this is matter for another thread.
Thx for all
Serge
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Upvote 0

Serge Bertet

Active Member
Licensed User
In fact it is in an example for CustomListView (CustomListView.b4a) found on this web site
B4X:
    For i = 1 To 3
        clv2.Add(CreateListItem($"Item #${i}"$, clv2.AsView.Width, 70dip), 70dip, $"Item #${i}"$)
    Next
I'll check your link.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
It is always difficult to help with small code snippets.
It is always much more efficient to post a small project showing the problem, or even post the whole project (at least for me).
Most of the time, the problem is not in the code snippet but somewhere else in the code.

In your last post you refer to CustomListView, but you should use xCustomListView.
 
Upvote 0
Top