O'Reilly logo

Android Design Patterns and Best Practice by Kyle Mew

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Constructing layout builders

So far in this book, all the layouts we have constructed have been static XML definitions. As you would expect, however, it is perfectly possible to construct and inflate UIs dynamically from our source code. Furthermore, Android layouts lend themselves very nicely to the builder pattern, as we saw with our alert dialog, as they are comprised of an ordered collection of smaller objects.

The following example will follow the builder design pattern to inflate a linear layout from a series of predefined layout views. As before, we will build up from interfaces to abstractions and concrete classes. We will create two kinds of layout item, a title or headline view and a content view. We then make several concrete examples ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required