Hello Folks. I'm using HorizontalScrollView to add and remove dinamically its items (on its inner panel) by code. I felt the need to make some items shifting dinamically keeping an internal reference on index position; i other words, i need to add item AT SPECIFIC INDEX, making the other items to shift as expected. AddView() method does not allow to specificy and index... but the ViewGroup view in the underlying Android world has an overload which allow to do it. It should be great having "AddViewAt()" method to giving more freedom to use.
Now, is there some workaround to control the indexes ? BringToFront() and SendToBack() move the items down and up, but is pretty limited.
Could give me some good suggestions ? My code could be great if i could add items at specific index. I could use Reflector calling AddView() with the overload i need, but i'm afraid this could confuse the underlying panel code logic.
You can manage the order of the views in a list, add views to the list using list.insertat and then send all the views from that position to the back.
Something like this:
B4X:
Sub AddViewAt(parent As Panel, new As View, Index As Int)
lst.InsertAt(Index,new)
panel1.addview(new,10%x * Index, 15%y ,20%x,10%y)
Dim v As View
For i = Index To lst.Size - 1
v = lst.Get(i)
v.Left = 10%x * i
v.SendToBack
Next
End Sub
You can manage the order of the views in a list, add views to the list using list.insertat and then send all the views from that position to the back.
Something like this:
B4X:
Sub AddViewAt(parent As Panel, new As View, Index As Int)
lst.InsertAt(Index,new)
panel1.addview(new,10%x * Index, 15%y ,20%x,10%y)
Dim v As View
For i = Index To lst.Size - 1
v = lst.Get(i)
v.Left = 10%x * i
v.SendToBack
Next
End Sub