Adding views to layout programatically

Recently while working on an Android project I needed to add several buttons to a layout dynamically. I wanted to create them on the fly from an array. That way whenever I need to add another all I would have to do is add another element to the array. The code wasn’t that straightforward and after a while I was able to figure out what to do. Below is what I came up with.

Continue reading