Android Question XUI CustomListView - Problem with GetScrollViewOffset

FrankBerra

Active Member
Licensed User
Longtime User
Hi everyone
i am trying to add many items to index 0 of a XUI CustomListView and immediately after each item added i want to scroll to the previous offset, taking into consideration the height of the new added element.
For doing this i modified the original sub of CostomListView like this:

B4X:
Private Sub InsertAtImpl(Index As Int, Pnl As B4XView, ItemSize As Int, Value As Object, InitialSize As Int)

Dim InitialPosition As Float
Dim FinalPosition As Float
InitialPosition = GetScrollViewOffset

.........<Original code Here>.......

FinalPosition = InitialPosition + p.Height + IncludeDividierHeight
SetScrollViewOffset(FinalPosition)
Log("New Position: " & GetScrollViewOffset)
End Sub

The problem is that even if FinalPosition is a number greater than 0 the instruction GetScrollViewOffset give me always 0.
(The number of items in the CustomListView are dozens, so i can scroll manually trough them and i expect that SetScrollViewOffset(FinalPosition) works correctly)

How can i obtain the correct value from GetScrollViewOffset that i have just set?
 

FrankBerra

Active Member
Licensed User
Longtime User
I am trying to create an endless scrolling effect for a chat application.
When i scroll to the top (to the item to position 0) i want to add 50 more items before the item at index 0.
The point is that the item ad index 0 must be still visible when adding the other 50 items.
So my idea is to add an item at position 0 (with CLV.InsertAt(0, Panel, "ID")) and then immediately add to the scrollview an offset with the same height of the added item.
Hope you understood my bad english...
 
Upvote 0

FrankBerra

Active Member
Licensed User
Longtime User
Because if i add 50 items before other items that i am looking at, the items that i am looking at shift down ad disappear from the screen.
I want to avoid this.
So i modified the class as explained in the first post. The question still remains:
With the following 2 instructions
B4X:
SetScrollViewOffset(FinalPosition)
Log("New Position: " & GetScrollViewOffset)
if i set the new ScrollView Offset, why in the following instruction (GetScrollViewOffset) i get always 0?
Is there a delay from setting the offset to retrieving the offset again?
What makes me more frustrated is that If i execute the code in debug mode by placing some BreakPoints the code GetScrollViewOffset gives me the right expected value.
 
Last edited:
Upvote 0

FrankBerra

Active Member
Licensed User
Longtime User
After a lot o failures and attempts i found the following solution:
I discovered that B4XView supports rotation so i rotated the whole CLV by 180 degrees (CLV.AsView.Rotation=180) and started to insert single items rotated by 180 degrees too (so they look as not rotated).
If i scroll the CLV to the top in reality it is scrolling to the bottom and at this point i add a new element to the bottom that on the screen appears to the top.
I felt surprised and everything works PERFECTLY!

If in the future i decide to recycle the code in B4i does the rotation still works? (Sorry i can't test on iOS because i don't own one at the moment)
 
Upvote 0
Top