Replace (update) a View in a ScrollableView in Titanium Mobile


/ Published in: JavaScript
Save to your folder(s)

It’s pretty straightforward, we loop the existing Views of the ScrollableView and copy each View, replacing the one to be change, to a new array. Then we tell the ScrollableView to use our new Views-array for it’s Views.
I hope this helps someone.


Copy this code and paste it in your HTML
  1. /**
  2.  * Replace (update) one view of a ScrollablView with a new one
  3.  *
  4.  * @param object The scrollableView
  5.  * @param object The old view to be replaced
  6.  * @param object The new view to replace the old one
  7.  * @return void
  8.  */
  9. function replaceView(scrollableView, oldView, newView)
  10. {
  11. // loop all the views in the scrollable view
  12. for (var i = 0, newViews = [], l = scrollableView.views.length; i < l; i++)
  13. {
  14. // replace the old view with the new one
  15. if (i == scrollableView.currentPage)
  16. newViews.push(newView);
  17. // leave the other views unchanged
  18. else
  19. newViews.push(scrollableView.views[i]);
  20. }
  21.  
  22. // update the scrollableView's views array with the new one
  23. scrollableView.views = newViews;
  24. }

URL: http://www.chlab.ch/blog/archives/mobile-development/replace-update-view-scrollableview-titanium-mobile

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.