Chapter 2 Flashcards
MVC
labeled model, controller, and view. architecture android applications are designed around. MVC states that any object in your application must be a model object, a view object, or a controller object.
model object
holds the applications data and ‘business logic’. have no knowledge of the user interface; their sole purpose is holding and managing data. EX: a user, a product in a store, a photo on a server, or a television show, or a true-false question. compose the model layer.
view objects
know how to draw themselves on the screen and how to respond to user input, like touches. simple rule of thumb is that if you see it on screen, then it is a view. view layer consists of the widgets that are inflated from activity.xml
Controller objects
tie the view and model objects together. they contain ‘application logic’. 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. Controller layer, at present, consists solely of QuizActivity (class extending Activity).
MVC flow with user input
user interacts with view object. View sends message to controller. Controller updates model objects. Controller takes data from model objects that its views are interested in. Controller updates view with changes in model objects.
Benefit of MVC
helps you design and understand an application.
mdpi
medium-density screens (~160dpi)
hdpi
high-density screens (~240dpi)
xhdpi
extra-high density screens (~320dpi)
why the R.java file contains only two resource ID’s for png in mdpi, hdpi, and xhdpi?
all you have to do is use this resource ID. when the app is run, the OS will determine the appropriate image to display on that particular device.
add imagebutton instead of button
change xml button to imagebutton. remove text, padding, drawable attributes and add src and contentdescription attributes. also change the button objects in your java code to imagebutton objects.