Android Question Remove customlistview item

omidaghakhani1368

Well-Known Member
Licensed User
Longtime User
Hi
I add 10 item to customlistview example below
B4X:
1: for i = 0 to 10
   2: dim p1 as panel
   3: p1.initialize("")
   4: customlistview1.add(p1,100,i)
   5: p1.loadlayout("frm1")
6: next
when i remove item from 10 items,and again remove item then get error that not exist index
i use index from line 4 variable i
 

LucaMs

Expert
Licensed User
Longtime User
I save index of each panel in button tag
when i click on button i get button tag (it is index) and then remove item with index
but after remove item,count of item in list minus 1 and not exist index
how i load all views?your meaning is load all item again?

You don't need to handle the index of items (at least, not in this case).
You should use the same method you can see in the example project
(you should use the names of your views instead of Button and clv3, of course):

B4X:
Sub Button_Click
    Dim index As Int
    index = clv3.GetItemFromView(Sender)

'    Dim pnl As Panel
'    pnl = clv3.GetPanel(index)
 
'    Dim lbl As Label
'    Dim chk As CheckBox
'    lbl = pnl.GetView(0)
'    chk = pnl.GetView(2)
'    lbl.Text = "Clicked!"
'    Msgbox("Item value: " & clv3.GetValue(index) & CRLF & "Check value: " & chk.Checked, "")
  
     ' This if you want remove the Item
     clv3.RemoveAt(index)
End Sub
 
Upvote 1

omidaghakhani1368

Well-Known Member
Licensed User
Longtime User
You don't need to handle the index of items (at least, not in this case).
You should use the same method you can see in the example project
(you should use the names of your views instead of Button and clv3, of course):

B4X:
Sub Button_Click
    Dim index As Int
    index = clv3.GetItemFromView(Sender)

'    Dim pnl As Panel
'    pnl = clv3.GetPanel(index)

'    Dim lbl As Label
'    Dim chk As CheckBox
'    lbl = pnl.GetView(0)
'    chk = pnl.GetView(2)
'    lbl.Text = "Clicked!"
'    Msgbox("Item value: " & clv3.GetValue(index) & CRLF & "Check value: " & chk.Checked, "")
 
     ' This if you want remove the Item
     clv3.RemoveAt(index)
End Sub
Thank you.the GetItemFromView method return parent panel index?
 
Upvote 0
Top