Master Android from first principles and begin the journey toward your own successful Android applications!
Dear Reader,
First, welcome to the world of Android! We’re entering a new era of mobile application development, one marked by open platforms and open source, to take ‘walled gardens’ and make them green houses for any and all to participate in. Android is relatively easy for developers, and I believe that this innovation will help generate a large ecosystem of developers and consumers within a very short time. This means that budding developers such as yourself will have many opportunities to design and build your own applications and you’ll have a huge and hungry customer base.
Second, welcome to the book! Its purpose is to start you on your way with building Android applications, and to help you master the learning curve. Android is already a rich framework, comparable in many ways to the richness Android of desktop Java environments. This means that there is a lot of cool stuff for you to pick up along your journey in order to create the slickest, most useful apps Android you can imagine.
The source code for the code samples in this book is all available from the Apress site, so you can stay as hands-on and practical as you like while I introduce you to the core of Android, and invite you to experiment with the various classes and APIs we’ll be looking at. By the time you’ve finished this book, you’ll be creating your own Android applications and asking yourself what your next great application will be…!
Enjoy!
Mark Murphy
A Bit About Inflation
A Bit About Inflation
In this case, “inflation” means the act of converting an XML layout specification into the actual tree of View
objects the XML represents. This is undoubtedly a tedious bit of code: take an element, create an instance of the specified View
class, walk the attributes, convert those into property setter calls, iterate over all child elements, lather, rinse, repeat.
The good news is that the fine folk on the Android team wrapped all that up into a class called LayoutInflater
that we can use ourselves. When it comes to fancy lists, for example, we will want to inflate Views
for each row shown in the list, so we can use the convenient shorthand of the XML layout to describe what the rows are supposed to look like.
In the preceding example, we inflate the R.layout.row
layout we created in the previous section. This gives us a View
object that, in reality, is our LinearLayout
with an ImageView
and a TextView
, just as R.layout.row
specifies. However, rather than having to create all those objects ourselves and wire them together, the XML and LayoutInflater
handle the “heavy lifting” for us.