I'm testing a part of my app to allow the user to LongClick on a CLV. The code in turn would add the Index to a List.
The user can then select another CLV row and it does the same, adds the Index to a List.
In the CLV LongClick code, my ActionBars (Panels) are manipulated to hide the "main bar" and show the "delete bar". They are panels with other views on them, like Labels and Buttons.
On the "delete bar" there is a Button - btnDelete. When pressed it cycles thru the List of Indexes and runs the CLV.RemoveAt(Index) code.
Here's the issue: the code only removes the first Index in the List and not the others. That is of course if the user selected more than one row in the CLV.
The zipped project is attached.
The btnDelete code is not working as desired.
Does the CLV.RemoveAt(Index) re-index the CLV indexes?
This code is for the "Default" type of B4A project:
The user can then select another CLV row and it does the same, adds the Index to a List.
In the CLV LongClick code, my ActionBars (Panels) are manipulated to hide the "main bar" and show the "delete bar". They are panels with other views on them, like Labels and Buttons.
On the "delete bar" there is a Button - btnDelete. When pressed it cycles thru the List of Indexes and runs the CLV.RemoveAt(Index) code.
Here's the issue: the code only removes the first Index in the List and not the others. That is of course if the user selected more than one row in the CLV.
The zipped project is attached.
The btnDelete code is not working as desired.
Does the CLV.RemoveAt(Index) re-index the CLV indexes?
This code is for the "Default" type of B4A project:
Activity_Create:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main")
SelectedItems.Initialize
Load_Data
End Sub
Load_Data:
Sub Load_Data
clvItems.Clear
For i = 0 To 20
clvItems.AddTextItem("Item " & i,i)
Next
End Sub
LongClick:
Private Sub clvItems_ItemLongClick(Index As Int, Value As Object)
pnlActionBar.Visible = False
pnlDeleteBar.Visible = True
Dim p As Panel = clvItems.GetPanel(Index)
p.Color = xui.Color_LightGray
SelectedItems.Add(Index)
lblDeleteTitle.Text = "Delete " & SelectedItems.Size
End Sub
btnDelete_Click:
Private Sub btnDelete_Click
Dim ItemCount As Int = SelectedItems.Size '<=== SelectedItems is a List
Log("ItemCount: " & ItemCount)
If ItemCount > 0 Then
For i = 0 To ItemCount - 1
Dim idx As Int = SelectedItems.Get(i)
Log(idx)
clvItems.RemoveAt(idx) '<=== should remove all items in List, BUT DOES NOT!
Next
ToastMessageShow(ItemCount & " items deleted.", False)
Else
ToastMessageShow("No Items selected!", False)
End If
End Sub