Indefinetelly Dynamically Expand A Newscrollview

Hi there,

I am trying to achieve the following:

I load a list of items from a remote server, and I show 5 of them in a scrollview. There are many more of the same item on the server, but I want to load them, only if the user reaches the bottom of the screen by scrolling. 

I want this to continue for ever, aka, as long as the user scrolls down, a new set of 5 items is loaded and added to the bottom of the page.

I have managed to add an item to the bottom of the page when the user scrolls doing the following inside the scrollview listener

 if event.limitReached then if "up" == direction then print( "Reached Top Limit" ) local myOwnItem = display.newRect(2, currentEndOfMyContent, 300, 100) myOwnItem:setFillColor(255, 0, 0) event.target:insert(myOwnItem) elseif "down" == direction then print( "Reached Bottom Limit" ) elseif "left" == direction then print( "Reached Left Limit" ) elseif "right" == direction then print( "Reached Right Limit" ) end end

But I havent managed to make the scrollview expand, so the screen never remains on the last item that I just added.

Is there a way to expand the scrollview after it has been made?

The documentation says : 

scrollWidth, scrollHeight (required)

Numbers. This is the width/height of the total scrollable content area. This cannot be changed after the ScrollView widget has been created.

Does this means that what I am trying to do is not doable with newScrollView?

Hi there,

I am trying to achieve the following:

I load a list of items from a remote server, and I show 5 of them in a scrollview. There are many more of the same item on the server, but I want to load them, only if the user reaches the bottom of the screen by scrolling. 

I want this to continue for ever, aka, as long as the user scrolls down, a new set of 5 items is loaded and added to the bottom of the page.

I have managed to add an item to the bottom of the page when the user scrolls doing the following inside the scrollview listener

if event.limitReached then if “up” == direction then print( “Reached Top Limit” ) local myOwnItem = display.newRect(2, currentEndOfMyContent, 300, 100) myOwnItem:setFillColor(255, 0, 0) event.target:insert(myOwnItem) elseif “down” == direction then print( “Reached Bottom Limit” ) elseif “left” == direction then print( “Reached Left Limit” ) elseif “right” == direction then print( “Reached Right Limit” ) end end

But I havent managed to make the scrollview expand, so the screen never remains on the last item that I just added.

Is there a way to expand the scrollview after it has been made?

The documentation says : 

Does this means that what I am trying to do is not doable with newScrollView?

There is a little bug at present where event.target is returning the scrollView’s _view group as opposed to the scrollView object. What this means is when you add the item to the scrollView via event.target it’s not getting inserted into the group correctly and thus not expanding the height dynamically.

The good news is that this issue has been fixed and will be available in a daily build soon.

For the time being you could do (the below code should fix your issue):

event.target.parent:insert( myOwnItem )

Thank you Danny,

For now, and in order to get around this, I used the newTableView, but it meant rewritting a lot of my code. But it works fine. (and it also gives a different problem at scrollToIndex, allready reported).

K.

Hi there,

I am trying to achieve the following:

I load a list of items from a remote server, and I show 5 of them in a scrollview. There are many more of the same item on the server, but I want to load them, only if the user reaches the bottom of the screen by scrolling. 

I want this to continue for ever, aka, as long as the user scrolls down, a new set of 5 items is loaded and added to the bottom of the page.

I have managed to add an item to the bottom of the page when the user scrolls doing the following inside the scrollview listener

if event.limitReached then if “up” == direction then print( “Reached Top Limit” ) local myOwnItem = display.newRect(2, currentEndOfMyContent, 300, 100) myOwnItem:setFillColor(255, 0, 0) event.target:insert(myOwnItem) elseif “down” == direction then print( “Reached Bottom Limit” ) elseif “left” == direction then print( “Reached Left Limit” ) elseif “right” == direction then print( “Reached Right Limit” ) end end

But I havent managed to make the scrollview expand, so the screen never remains on the last item that I just added.

Is there a way to expand the scrollview after it has been made?

The documentation says : 

Does this means that what I am trying to do is not doable with newScrollView?

There is a little bug at present where event.target is returning the scrollView’s _view group as opposed to the scrollView object. What this means is when you add the item to the scrollView via event.target it’s not getting inserted into the group correctly and thus not expanding the height dynamically.

The good news is that this issue has been fixed and will be available in a daily build soon.

For the time being you could do (the below code should fix your issue):

event.target.parent:insert( myOwnItem )

Thank you Danny,

For now, and in order to get around this, I used the newTableView, but it meant rewritting a lot of my code. But it works fine. (and it also gives a different problem at scrollToIndex, allready reported).

K.