Download presentation
Presentation is loading. Please wait.
Published byTamsin Townsend Modified over 9 years ago
1
ANDROID AND MODEL / VIEW / CONTROLLER
2
Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are characterized as: Structural patterns that depict the bigger picture of how classes (things) fit together Adapter, MVC Creational patterns depict how objects are created Factory pattern Behavioral patterns describe the interaction between objects
3
Slide 3 MVC (Introduction) Design pattern with a clear separation between application logic and the user interface In Android, all objects fall into either a model view controller
4
Slide 4 MVC (Model - 1) The model manages the information and notifies the observers when the information changes It represents the data on which the application operates The model provides the persistent storage of data, which is manipulated by the controller In this chapter, we are modeling a true / false question
5
Slide 5 MVC (Model - 2) Model has no knowledge of the user interface That’s the responsibility of the view In Android, these are custom classes that you typically create
6
Slide 6 MVC (View) The view displays the data It takes input from user It renders the model data into a form (screen) to display to the user There can be several views associated with a single model Usually for different devices If it’s visible to the user, it’s a view
7
Slide 7 MVC (View) The view knows how to draw itself on the screen Together, all of the different view objects make up the view layer Rendering a view is often called inflating a view
8
Slide 8 MVC (Controller 1) The controller handles all requests coming from the view or (user interface) The data flow to whole application is managed by the controller It forwards the request to the appropriate handler Only the controller is responsible for accessing the model and rendering it into various UIs (views)
9
Slide 9 MVC (Controller 2) The controller ties the model and views together Controllers are designed to respond to various events triggered by view objects and to manage the flow of data to and from model objects and the view layer
10
Slide 10 MVC (Illustration)
11
Slide 11 Chapter 2 MVC Implementation
12
Slide 12 MVC Benefits Separates the business logic from the user interface We can have multiple views for different devices Applications tend to be more structured thereby making them easier to understand Code reusability tends to increase
13
Slide 13 Adding a Java Class (1) The project in the first chapter had a single class In this chapter, you will add a second class that will implement the model
14
Slide 14 Adding a Java Class (2) Click File, New, Class to create a new class Give the class a name
15
Slide 15 Adding a Java Class (3)
16
Slide 16 Accessors and Mutators In C# we create what are called property procedures to implement properties Remember that properties store data about an object In Java, we create method pairs called accessors and mutators Accessers read a property Mutators update a property
17
Slide 17 Accessors Both store data in a hidden variable Accessors typically begin with the prefix get Boolean accessors typically begin with the prefix is Typically the value is stored in a hidden variable
18
Slide 18 Mutators Both store data in a hidden variable Mutators typically begin with the prefix “set”
19
Slide 19 Example The following contain accessors and mutators
20
Slide 20 Icons (Introduction) Icons are stored as external files Multiple versions of an icon are typically needed to support different resolutions Medium (mdpi) (about 160 dpi) High (hdpi) (about 240 dpi) Extra-high (xhdpi) (about 320 dpi) Low density devices are considered obsolete
21
Slide 21 Icons (Implementation) Icons are stored in the res folder By convention, there are subdirectories that store icons of the various resolutions Android figures out which icon (resource) to use based on the device resolution png, jpg, gif formats are supported among others
22
Slide 22 Icons (Illustration)
23
Slide 23 Reading Resources in XML The syntax to read a resource is similar to the process to read a string A reference to a string resource begins with @string A reference to a drawable resource begins with @drawable
24
Slide 24 Reading a Resource (Example) Read and display the resource named arrow_right
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.