Top Banner
Android Graphical User Interface
52

01 10 - graphical user interface - others

May 19, 2015

Download

Technology

Siva Reddy
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 01  10 - graphical user interface - others

Android

Graphical User Interface

Page 2: 01  10 - graphical user interface - others

Agenda

Familiarize with the main types of GUI components

Layouts

Basic Widgets

Others

Page 3: 01  10 - graphical user interface - others

Menus

Page 4: 01  10 - graphical user interface - others

Using Menus

Menus is not consuming ‘much’ view space.

Android provides two types of menu known

as: options menu and context menu.

The options menu is triggered by pressing the

hardware Menu button on the device, while

The context menu is raised by a tap-and-hold on

the widget associated to the menu.

Page 5: 01  10 - graphical user interface - others

Using Menus

Example: Using an option menu

Options

available in

this context

Press Menu

Button

A max of six entries per

menu. Excess will be

displayed as part of the

More option

Page 6: 01  10 - graphical user interface - others

Example: Using an option menu

Available

Options in

this

context

Press Menu

button

Using Menus

Page 7: 01  10 - graphical user interface - others

Example :

Dealing with SMS

(text-messages)

by using the built-

in Messaging

app’s

context menu

Tap-&-Hold

Using Menus

Page 8: 01  10 - graphical user interface - others

Option and Context Menus may include:

1. Text

2. Icons

3. Radio Buttons

4. Check Boxes

5. Sub-menus

6. Short-cut keys

Page 9: 01  10 - graphical user interface - others

Example 1: Option Menu

Page 10: 01  10 - graphical user interface - others

Example 1: Option Menu

Page 11: 01  10 - graphical user interface - others

Example 1: Context Menu

Page 12: 01  10 - graphical user interface - others

Example 1: Using Option and Context Menu

The app shows two text boxes. Menus are used to change text’s size, color, and

style.

Page 13: 01  10 - graphical user interface - others

Example 1: Using Option and Context Menu

The app shows two text boxes. Menus are used to change text’s size, color, and style.

Page 14: 01  10 - graphical user interface - others

Example 1: Using Option and Context Menu

The app shows two text boxes. Menus are used to change text’s size, color, and style.

Page 15: 01  10 - graphical user interface - others

Example 1: Using Option and Context Menu

Page 16: 01  10 - graphical user interface - others

Example 1: Using Option and Context Menu

Page 17: 01  10 - graphical user interface - others

Example 1: Using Option and Context Menu

Page 18: 01  10 - graphical user interface - others

Example 1: Using Option and Context Menu

Page 19: 01  10 - graphical user interface - others

Comments on Creating an Option & Context

Menu

Step1.Indicate which widget(s) on your activity have context menus. To do this, call

registerForContextMenu(theWidget)

supplying the View that is the widget needing a context menu.

Step2.

Implement onCreateContextMenu(…), populate your menu adding

text, icons, etc. to the different options.Use input menu parameter

to determine which menu to build (assuming your activity has

more than one).

The onCreateContextMenu()method gets the Context Menu itself, the View the context

menu is associated with, and a ContextMenu. ContextMenuInfo, which tells you which item in

the list the user did the tap-and-hold over, in case you want to customize the context menu

based on that information

Page 20: 01  10 - graphical user interface - others

Comments on Creating an Option & Context Menu

•onCreateContextMenu() is called each time the context menu

is requested.

•Unlike the options menu (which is only built once per activity),

context menus are discarded once they are used or dismissed.

•To find out when a context menu choice was chosen,

implement onContextItemSelected() on the activity.

Page 21: 01  10 - graphical user interface - others

Example 1: Using Option and Context Menu

Page 22: 01  10 - graphical user interface - others

Selection Widgets

Page 23: 01  10 - graphical user interface - others

Selection Widgets

Radio Buttons and Check Buttons are suitable for selecting

from a smallset of options.

When the pool of choices is larger other widgets are more

appropriate, those include classic UI controls such as: list

boxes, combo boxes, drop-down lists, picture galleries, etc.

Android offers a framework of data adapters that provide a

common interface to selection lists ranging from static arrays to

database contents.

Selection views –widgets for presenting lists of choices –are

handed an adapter to supply the actual choices.

Page 24: 01  10 - graphical user interface - others

Displaying/Selecting Options

Page 25: 01  10 - graphical user interface - others

Using Array Adapter

The easiest adapter to use is ArrayAdapter–all you need to do is wrap one of these

around a Java array or java.util.List instance, and you have a fully functioning

adapter:

The Array Adapter constructor takes three parameters:

1.The Context to use (typically this will be your activity instance)

2.The resource ID of a view to use (such as the built-in system resource

android.R.layout.simple_list_item_1as shown above)

3.The actual (source) array or list of items to show

Page 26: 01  10 - graphical user interface - others

Example 1: A simple list

Instead of Activity we will use a ListActivity which is an Android class specializing in

the use of ListViews.

Page 27: 01  10 - graphical user interface - others

Example 1: A simple list (Activity)

Instead of Activity we will use a ListActivity which is an Android class specializing in

the use of ListViews.

Page 28: 01  10 - graphical user interface - others

Example 1: A simple list (Adapter)

Page 29: 01  10 - graphical user interface - others

Example 1: A simple list (out put)

Page 30: 01  10 - graphical user interface - others

Selection Widgets - Spin Control

In Android, the Spinner is the equivalent of the drop-down

selector.

Spinners have the same functionality of a ListView but take

less space.

As with ListView, you provide the adapter for linking data to

child views using setAdapter()

Add a listener object to capture selections made from the list

with setOnItemSelectedListener().

Use the setDropDownViewResource()method to supply

the resource ID of the multi-line selection list view to use.

Page 31: 01  10 - graphical user interface - others

Example - Using the Spinner (Demo)

Page 32: 01  10 - graphical user interface - others

Example - Using the Spinner (Xml Layout)

Page 33: 01  10 - graphical user interface - others

Example - Using the Spinner (Activity)

Page 34: 01  10 - graphical user interface - others

Example - Using the Spinner (Events)

Page 35: 01  10 - graphical user interface - others

Selection Widgets - GridView

GridView is a ViewGroup that displays items in a two-dimensional, scrollable

grid.

The grid items are automatically inserted to the layout using a ListAdapter.

Page 36: 01  10 - graphical user interface - others

Example . Grid View (Xml Layout)

Page 37: 01  10 - graphical user interface - others

Example . Grid View (Activity)

Page 38: 01  10 - graphical user interface - others

Example . Grid View (Events)

Page 39: 01  10 - graphical user interface - others

Selection Widgets - AutoCompleteTextView

With auto-completion, as the user types, the text is treated as

a prefix filter, comparing the entered text as a prefix against a

list of candidates.

Matches are shown in a selection list that, like with Spinner, folds

down from the field.

The user can either type out a new entry (e.g., something not in

the list) or choose an entry from the list to be the value of the field.

AutoCompleteTextView subclasses EditText, so you can configure

all the standard look-and-feel aspects, such as font face and color.

AutoCompleteTextView has a

android:completionThresholdproperty, to indicate the

minimum number of characters a user must enter before the

list filtering begins.

Page 40: 01  10 - graphical user interface - others

Example . Auto Complete TextView

Page 41: 01  10 - graphical user interface - others

Example . AutoCompleteTextView (Xml layout)

Page 42: 01  10 - graphical user interface - others

Example . Auto Complete TextView (Activity)

Page 43: 01  10 - graphical user interface - others

Example . AutoCompleteTextView (Events)

Page 44: 01  10 - graphical user interface - others

Selection Widgets - Gallery Widget

The Gallery widget provides a set of options depicted as images.

Image choices are offered on a contiguous horizontal mode, you

may scroll across the image-set.

Page 45: 01  10 - graphical user interface - others

Example - Gallery Widget (XML Layout)

Page 46: 01  10 - graphical user interface - others

Example - Gallery Widget (Activity)

Page 47: 01  10 - graphical user interface - others

Example - Gallery Widget (Events)

Page 48: 01  10 - graphical user interface - others

Example - Gallery Widget (Adapter)

Page 49: 01  10 - graphical user interface - others

Example - Gallery Widget (Adapter - cont)

Page 50: 01  10 - graphical user interface - others

Example - Gallery Widget (Adapter - cont)

Page 51: 01  10 - graphical user interface - others

Example - Gallery Widget (Adapter - cont)

Page 52: 01  10 - graphical user interface - others

Questions?