Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Model-View-Controller (MVC) is a graphical user interface (GUI) application paradigm that has recently taken hold. The concept involves the developer considering three main areas when developing an application. These areas can be kept as independent as possible. The model, loosely analogous to the process in the traditional Input-Process-Output (IPO) model, represents what the application does and the coding behind what it is intended to do. The view, analogous to the output in the IPO model, is concerned with rendering the results on the display. The controller, analogous to the input in the IPO model, deals with how the user will interact with the application, including mouse movements, button clicks, and so on.
When developing Android applications, we can easily isolate the view from the model and controller components. The view or layout of components is written in XML format in the main.xml file. Once the programmer determines which controls are necessary for the application, such as lists, text fields, buttons, and so on, he can plan and code their arrangement, size, labels, fonts, and colors in the main.xml file. Indeed, after the application is written, should the programmer decide he does not like the user interface’s aesthetics, he can make changes without altering the Java classes and methods that produce the model and controller components of the MVC model. For instance, would two input fields work better side by side, or one atop the other? The programmer can try both arrangements by altering the main.xml file only without having to find their references in Java code and making changes there. In the sections that follow, we will look at how the main.xml file works. But before we get into that, Table 3.1 offers a quick refresher on the rules and syntax of XML files.
Table 3.1 Key XML Structure Elements
Following are the rules for XML files:
1. All XML elements must have opening and closing tags.
2. XML tags are case sensitive.
3. XML elements must be properly nested.
ex.
<tag1>
<tag2>
</tag2>
</tag1>
4. XML documents must have a root element. A single tag pair must surround all other elements of the document. This is the root element.
5. XML attribute values must be quoted using either single or double quotes.