Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

ScrollableView removeView and addView behaviour on android

I just wanted to make a note of this, just in case anyone else needs it.

When removing a view that has been previously added to a scrollable view, currently on android it is very important to remove the views that exist after it in the index BEFORE removing the view itself, otherwise you will experience an out of bounds index error. Once the view you want to remove is gone, add those that you removed back to the view index.

For example, if you have view0,view1,view2,view3,view4,view5 added to your scrollableView and you want to remove view3, then keep to the following sequence:

removeView: view5, view4, view3
addView: view4, view5

I will confer with the Ti devs to determine whether this is expected behaviour, and report back accordingly.

— asked October 22nd 2010 by Paul Dowsett
  • android
  • removeview
  • scrollableview
  • Don has confirmed that this is a bug. See this ticket.

    — commented November 4th 2010 by Paul Dowsett
  • This is a test for Hal at Hal's request

    — commented November 13th 2010 by Blain Hamon

3 Answers

  • This is a test for Hal at Hal's request

    — answered November 13th 2010 by Blain Hamon
  • Another test. Please ignore.

    — answered February 24th 2011 by Paul Dowsett
  • Even though this ticket shows the bug has been fixed. There still is a bug.
    If you have the scrollableView selected on the view that you remove, then on Android it will remove the view, but not replace it.. It should scroll either to the previous or last view.
    You can manually call scrollToView to fix this.. but, when there's only 2 views left, and you remove one of those. Then it becomes stuck on an empty view. There is no way of getting back to the last remaining view and the scrollToView does nothing (as you can test in the code below) and the scroll event does not fire either.

    This works fine on iPhone, it' just Android that has the issue.
    I'm testing on Titanium 1.6.1 and Android Api's 2.2

    Sample code with 2 views and a scrollable view:

    To test this. Manually scroll the view to "View 1" the green one. Then click on the button: "Remove View 1"
    Expected result: The view gets removed and it scrolls back to view0. (this happens on iPhone)
    On Android: The scrollableView remains blank, and there is no way to get back to view0.

    — answered March 22nd 2011 by Daniel Tome
    1 Comment
    • The only temporary fix (aka Hack) for this is to remove the scrollableView and add it back with just that view.

      — commented March 22nd 2011 by Daniel Tome
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.