Limitations of the layout XML format

One of the most obvious limitations of the layout XML format is that you can't dynamically populate part of the Activity based on external variables there are no loops or methods in the XML file.

In our example, this limitation shows itself in the form of our empty LinearLayout. Because each question has any number of possible answers, we need a varying number of buttons in the group. For our purposes, we will create the Button objects and put them into the LinearLayout as part of the Java code.

The other place the XML layout format falls down is dynamically referencing external resources. This can be seen in our example, where we put placeholder text in the android:text attribute on the TextView element question ...

Get Android User Interface Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.