Search code examples
iostitaniumscrollviewappcelerator-titanium

how to programmatically add view to scrollview in alloy


I'm struggling to implement adding dynamic content to the scrollview in the controller. In my xml, I've a horizontal scrollview. I need to add multiple views to the scrollview programmatically from the controller. How can I do it programmatically in Appcelerator Alloy ?


Solution

  • 2 ways possible, depending on the complexity of the view you want to add.

    1)

    Create a controller for the view, then add it

    $.scrollViewId.add(Alloy.createController('subViewController').getView());
    

    2) If it is a simple view, just do

    $.scrollViewId.add(Ti.UI.createView());
    

    Since this is a pretty basic thing to do in Titanium/Alloy, you might want to dive into the documentation about Alloy https://docs.appcelerator.com/platform/latest/#!/guide/Alloy_Concepts

    There are some extra chapters about Alloy in the menu on the left