hit3328 - chapter0601 - menus and lists

36
HIT3328 / HIT8328 Software Development for Mobile Devices Dr. Rajesh Vasa, 2011 1 Twitter: @rvasa Blog: http://rvasa.blogspot.com Lecture 06 Menus and Lists

Upload: yhal-htet-aung

Post on 05-Dec-2014

345 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: HIT3328 - Chapter0601 - Menus and Lists

HIT3328 / HIT8328 Software Development for Mobile DevicesDr. Rajesh Vasa, 2011

1

Twitter: @rvasa Blog: http://rvasa.blogspot.com

Lecture 06Menus and Lists

Page 2: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 20112

Lecture Overview

•Working with Menus

•Using Frame Layout

•Adapters and Working with Simple Lists

Page 3: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 20113

Menus

•Android offers a ‘Menu’ button, iOS does not

•Menus’ can be customised per activity

Menus have a label and an icon

Icon is strongly recommended by the Android UI guidelines

Menu

Icons at different resolutions should be provided (ideally)

Page 4: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 20114

Creating a MenuName App (from Lecture

5)

Menus are defined as a resource

We can use icons provided by Android SDK (recommended)

We can use icons provided by Android SDK (recommended)

Page 5: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 20115

Menus are Resources

Convention is to place it in ‘menu’ folder

Page 6: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 20116

Wiring up a Menu to Show

Call back method that we have to write

Resource Identifier

XML Resource file is converted (inflated) into a Menu object that will be rendered

(shown) on screen

XML Resource file is converted (inflated) into a Menu object that will be rendered

(shown) on screen

Page 7: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 20117

Handling Menu Click

Call back method that we have to write

Page 8: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 20118

Toasting a Message

•There is often a need to show a message for a short period and then fade on mobile devices

•Android offers this via the Toast utility

Page 9: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 20119

Toasting a Message

On Click

Message displayed for a

second

Page 10: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201110

Creating a Toast

Duration can be customisedAndroid offers Toast.LENGTH_LONG,

Toast.LENGTH_SHORT as built in defaults

Duration can be customisedAndroid offers Toast.LENGTH_LONG,

Toast.LENGTH_SHORT as built in defaults

Page 11: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201111

Lecture Roadmap - Where are we?•Working with Menus

•Using Frame Layout

•Adapters and Working with Simple Lists

Page 12: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201112

Frame Layout Offers Overlays

•We often need a way to overlay multiple views (or layouts) on top of each other

• Often with variation in transparency

• Frame Layout offers us this feature

• Frame Layout is also used to help create Tab Panes in Android

Page 13: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201113

Simple Frame Layout (Light Bulb)

Button is placed on top of Image View On / Off Images are also placed on top of each other

Page 14: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201114

Frame Layout - Code

2 Image Views and 1 Button in the same layout

Page 15: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201115

Frame Layout - Code

We control visibility explicitlyWe control visibility explicitly

Page 16: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201116

Light Bulb Logic

We flip the visibility of the images

Method is triggered onClickMethod is triggered onClick

Page 17: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201117

Lecture Roadmap - Where are we?•Working with Menus

•Using Frame Layout

•Adapters and Working with Simple Lists

Page 18: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201118

A Simple List App.

Displays Latitude and Longitude of a location

Page 19: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201119

Constituents of a List based screen

ListView

Text Views

Page 20: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201120

Lists get data via an Adapter

ListView

Data Source

Adapter

Page 21: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201121

Adapter Formats Data for Display

ListView

Data Source

Adapter

Data is formatted for display via customised layout attached to the

Adapter

Data is formatted for display via customised layout attached to the

Adapter

Page 22: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201122

List Views are very flexible

We specify the layout for each line

item of a list

Layout can be provided as a resource file (XML)

Page 23: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201123

Adapter Feeds data to List View

ListView

Data Source

Adapter

Data Source feeds data to the Adapter for

formatting

Data Source feeds data to the Adapter for

formatting

Page 24: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201124

Adapter Offers Separation of Concerns

ListView

Data Source

Adapter

Data Source can be an array, collection object, external database, or an

external server

Data Source can be an array, collection object, external database, or an

external server

Page 25: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201125

Simple List App.

ListView

Data Source

Adapter

Domain Model: HashMap (Cities, Location)

(Cities names)

(Simple Item Layout)

Page 26: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201126

Domain Model

Ideally, you read an external resource(Above data is hard-coded to illustrate concept)

Page 27: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201127

Wiring up Data - Adapter - ListView

Activity extends ListActivity

We are using an Array Adapter (others are available / you can

provide your own)

Page 28: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201128

Wiring up Data - Adapter - ListView

We are using SDK provided layout style(we can also write our own as an Layout XML)

Page 29: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201129

Wiring up Data - Adapter - ListView

We are setting the data source to use

Page 30: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201130

Wiring up Data - Adapter - ListView

Tell the List View to display from adapter

Page 31: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201131

Wiring up Data - Adapter - ListView

Only one ListView can receive data via the default

setListAdapter in an Activity

Page 32: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201132

Activity Layout

ListView that will receive data provided via setListAdapter

Page 33: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201133

Activity Layout

ListView that will receive data provided via setListAdapter

Special built-in

identifier

Special built-in

identifier

Page 34: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201134

Handling List Click Event

This call back is provided by the parent (List Activity) class -- we

override it

This call back is provided by the parent (List Activity) class -- we

override it

Page 35: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201135

But, what about complex lists?

Key concepts are the same

We will cover it later in depth

(if you are curious, look at examples online)

Page 36: HIT3328 - Chapter0601 - Menus and Lists

R. Vasa, 201136

Lecture Summary

•Working with Menus

•Using Frame Layout

•Adapters and Working with Simple Lists