Posted By

chlab on 05/24/11


Tagged

view replace mobile Titanium scrollableview


Versions (?)

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


 / Published in: JavaScript
 

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

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.

  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. }

Report this snippet  

You need to login to post a comment.