Android - Add views in a loop


Sometimes you need to dynamically create an unknown number of views - for example rows of data in a table. Because you cannot add the same view more than once without recreating it in a new variable, this is not as straight forward as one would think.

Take a look at the example below which loops through an array of information, then for each element, creates a view, adds that view to a list of views then loops through the list of views and appends each one to a LinearLayout element..

Facebook Twitter Google+ LinkedIn Buffer
Leave us a Comment

Connect With Us

Get our monthly newsletter with tech tips for business professionals