Search code examples
androidloopsandroid-custom-view

Custom view by code like this


Hello I want to add custom view by code and make it go down in scroll view (the scroll view is by xml but I want the costum view to be automatic by Java code) create by loop and I don't know how to do that:

a busy cat

Thanks for helping Asaf.


Solution

  • You can create a LinearLayout wrapper with vertical orientation programatically or through xml so in your code, i guess you should have a loop (for.while,etc) there you can instance your custom views and add it to your LinearLayour with:

    LinearLayout layout = new LinearLayout();
    
    for(something)
    {
    CustomView custom = new CustomView();
    // changes to yours custom view
    
    layout.addView(custom);
    }
    

    Good luck