Serge Bertet Active Member Licensed User Longtime User Aug 4, 2018 #1 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 Code: Copy PlayListView.Clear or Code: Copy 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
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 Code: Copy PlayListView.Clear or Code: Copy 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 Aug 4, 2018 #2 Clear should remove all items from the list. Can you post all the related code? - Colin. Upvote 0
Serge Bertet Active Member Licensed User Longtime User Aug 4, 2018 #3 Here is the code used to refresh the listview: Code: Copy 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
Here is the code used to refresh the listview: Code: Copy 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
Computersmith64 Well-Known Member Licensed User Longtime User Aug 4, 2018 #4 Serge Bertet said: Here is the code used to refresh the listview: Code: Copy 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 Click to expand... 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 said: Here is the code used to refresh the listview: Code: Copy 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 Click to expand... 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
Serge Bertet Active Member Licensed User Longtime User Aug 4, 2018 #5 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: Code: Copy Do While PlayListView.Size > 0 PlayListView.RemoveAt(0) Loop with no result. Serge Last edited: Aug 4, 2018 Upvote 0
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: Code: Copy Do While PlayListView.Size > 0 PlayListView.RemoveAt(0) Loop with no result. Serge
LucaMs Expert Licensed User Longtime User Aug 4, 2018 #6 Your code should work; at least you can add a Sleep(0) after PlayListView.Clear, to allow the GUI refreshing. [I suggest to use names like lvPlay (where the prefix lv means ListView, of course, so you "save" characters) and, mainly, to use xCustomListview] Upvote 0
Your code should work; at least you can add a Sleep(0) after PlayListView.Clear, to allow the GUI refreshing. [I suggest to use names like lvPlay (where the prefix lv means ListView, of course, so you "save" characters) and, mainly, to use xCustomListview]
klaus Expert Licensed User Longtime User Aug 4, 2018 #7 Can you post a small project showing the problem, or post your project. The ListView.Clear method clears all items. So, the problem seems to be somewhere else in your code. Upvote 0
Can you post a small project showing the problem, or post your project. The ListView.Clear method clears all items. So, the problem seems to be somewhere else in your code.
M Mahares Expert Licensed User Longtime User Aug 4, 2018 #8 klaus said: So, the problem seems to be somewhere else in your code Click to expand... Could it be that he is not closing the cursor before he generates the new list, so it is doubling up the items: csr.close Upvote 0
klaus said: So, the problem seems to be somewhere else in your code Click to expand... Could it be that he is not closing the cursor before he generates the new list, so it is doubling up the items: csr.close
klaus Expert Licensed User Longtime User Aug 4, 2018 #9 I dont think so. But he could try it. Upvote 0
Serge Bertet Active Member Licensed User Longtime User Aug 4, 2018 #10 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
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
LucaMs Expert Licensed User Longtime User Aug 4, 2018 #11 Serge Bertet said: 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 Click to expand... https://www.b4x.com/android/forum/threads/b4x-smart-string-literal.50135/#content BTW, if you want use it to create query strings, I highly recommend you to use the "versions 2" of the SQL queries (parametrized queries): Starter.db.ExecQuery2(... (also: ExecNonQuery2 and ExecQuerySingleResult2). Upvote 0
Serge Bertet said: 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 Click to expand... https://www.b4x.com/android/forum/threads/b4x-smart-string-literal.50135/#content BTW, if you want use it to create query strings, I highly recommend you to use the "versions 2" of the SQL queries (parametrized queries): Starter.db.ExecQuery2(... (also: ExecNonQuery2 and ExecQuerySingleResult2).
Serge Bertet Active Member Licensed User Longtime User Aug 4, 2018 #12 In fact it is in an example for CustomListView (CustomListView.b4a) found on this web site Code: Copy 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
In fact it is in an example for CustomListView (CustomListView.b4a) found on this web site Code: Copy For i = 1 To 3 clv2.Add(CreateListItem($"Item #${i}"$, clv2.AsView.Width, 70dip), 70dip, $"Item #${i}"$) Next I'll check your link.
klaus Expert Licensed User Longtime User Aug 4, 2018 #13 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
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.
LucaMs Expert Licensed User Longtime User Aug 4, 2018 #14 klaus said: In your last post you refer to CustomListView, but you should use xCustomListView. Click to expand... "Unfortunately" its classe name is CustomListView. Upvote 0
klaus said: In your last post you refer to CustomListView, but you should use xCustomListView. Click to expand... "Unfortunately" its classe name is CustomListView.