CMPE277_Lec2_Android_MVC_Activity.pdf

CMPE277_Lec2_Android_MVC_Activity.pdf - CMPE 277 Activities...

Info icon This preview shows pages 1–16. Sign up to view the full content.

View Full Document Right Arrow Icon
CMPE 277 COMPUTER ENGINEERING 1 CMPE 277 Instructor: Charles Zhang Fall 2017 Activities, MVC, and Intents
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CMPE 277 COMPUTER ENGINEERING 2 q Intro to Activities q Activity Life Cycles q MVC q Intents q Android User Interface Outline
Image of page 2
CMPE 277 COMPUTER ENGINEERING 3 What is Activity? Source: http://developer.android.com/reference/android/app/Activity.html https://play.google.com/store/apps/details?id=com.imangi.templerun&hl=en q An activity is a single, focused thing that the user can do q Responsible for managing user interaction with a screen of information q Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CMPE 277 COMPUTER ENGINEERING 4 Layout and Widgets q A layout defines a set of user interface widgets and their position on the screen q Made up of widget definitions written in XML q Each definition is used to create a widget that appears on screen, like a button or some text
Image of page 4
CMPE 277 COMPUTER ENGINEERING 5 Recommended activity and layout naming convention q Camel casing for activities q Reverse snake casing for layouts q Reverses the order of the activity name q All lowercase q Underscores between words q Naming style recommended for other resources too
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CMPE 277 COMPUTER ENGINEERING 6 Layout Specification in Detail q Whatever
Image of page 6
CMPE 277 COMPUTER ENGINEERING 7 Hierarchical layout of widgets and attributes
Image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CMPE 277 COMPUTER ENGINEERING 8 From Layout XML to View Objects q When an activity is created, it needs a UI to manage q The onCreate(Bundle) method is called upon activity creation q You call the setContentView(int layoutResID) within onCreate(Bundle) to create the UI
Image of page 8
CMPE 277 COMPUTER ENGINEERING 9 Typical Things to Do in OnCreate q Inflating widgets and putting them on screen q Typically through a call to setContentView(int) q Getting references to inflated widgets q Setting listeners on widgets to handle user interaction q Connecting to external model data
Image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CMPE 277 COMPUTER ENGINEERING 10 Resources and Resource IDs q A resource is a piece of your application that is not code q Image files, audio files, and XML files q Lives in a sub dir (layout, values, etc) within res q To access a resource in code, you use its resource ID defined in R.java
Image of page 10
CMPE 277 COMPUTER ENGINEERING 11 Adding IDs to Widgets
Image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CMPE 277 COMPUTER ENGINEERING 12 Wiring up Widgets q Define member variables in your activity q Use findViewById to locate the instance of view
Image of page 12
CMPE 277 COMPUTER ENGINEERING 13 Event-Driven Programming: Set Listeners Listener interfaces defined for various events You may use anonymous event handlers
Image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CMPE 277 COMPUTER ENGINEERING 14 Android Build Process
Image of page 14
CMPE 277 COMPUTER ENGINEERING 15 Android Model View Controller (MVC) - Model q A model object holds the application’s data.
Image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 16
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern