Chapter 9: Customize! Navigating with Tabs on a Tablet App

Similar documents
Getting Started with Android Programming (5 days) with Android 4.3 Jelly Bean

UNIVERSITY AUTHORISED EDUCATION PARTNER (WDP)

Using Adobe Dreamweaver CS4 (10.0)

Specialized Android APP Development Program with Java (SAADPJ) Duration 2 months

Appendix A How to create a data-sharing lab

Spike Tech Tip: How to use your online, cloud-based tools for Spike

MICROSOFT OUTLOOK 2010 WORK WITH CONTACTS

CHAPTER 1: INTRODUCTION TO ANDROID, MOBILE DEVICES, AND THE MARKETPLACE

OneDrive for Business User Guide

Homeschool Programming, Inc.

KeePass Getting Started on Windows

How to create buttons and navigation bars

Android Developer Fundamental 1

Android Programming. Høgskolen i Telemark Telemark University College. Cuong Nguyen,

App Inventor Drum Machine Instructions (Project #1) (Version 2 of App Inventor) Description:

Guide to Using Citrix at SLU (Windows)

ONLINE MARKETING CENTER. User Guide

Creating Reports with Microsoft Dynamics AX SQL Reporting Services

Knowledgebase Article

INTRODUCTION TO ANDROID CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 11 02/15/2011

OneDrive for Business User Guide

TRIM: Web Tool. Web Address The TRIM web tool can be accessed at:

ORACLE BUSINESS INTELLIGENCE WORKSHOP

Xamarin Android Application Development

Android Application Development Lecture Notes INDEX

Step-by-Step Instructions Download and Transfer of OverDrive Titles to Devices!

Steps to Create a Database

DocuSign for SharePoint Online v2.4

Microsoft PowerPoint 2008

Oracle Business Intelligence Publisher: Create Reports and Data Models. Part 1 - Layout Editor

OneDrive for Business User Guide

Crystal Print Control Installation Instructions for PCs running Microsoft Windows XP and using the Internet Explorer browser

Objectives. Understand databases Create a database Create a table in Datasheet view Create a table in Design view

GOOGLE DOCS APPLICATION WORK WITH GOOGLE DOCUMENTS

Initial Setup of Microsoft Outlook with Google Apps Sync for Windows 7. Initial Setup of Microsoft Outlook with Google Apps Sync for Windows 7

ITG Software Engineering

How to install and use the File Sharing Outlook Plugin

Virtual Exhibit 5.0 requires that you have PastPerfect version 5.0 or higher with the MultiMedia and Virtual Exhibit Upgrades.

MICROSOFT ACCESS 2007 BOOK 2

2. Click the download button for your operating system (Windows, Mac, or Linux).

Google Android Syllabus

Mobile App Design and Development

Project Server Plus Risk to Issue Escalator User Guide v1.1

Tenet Enterprise Application Portal. Access via ipad & iphone

SPHOL326: Designing a SharePoint 2013 Site. Hands-On Lab. Lab Manual

Teacher References archived classes and resources

Entering the example employee satisfaction survey in Survey Crafter Professional s Survey Designer window

Adobe Dreamweaver CC 14 Tutorial

Connecticut Hazardous Waste Manifests Database

Table of Contents. 1. Content Approval...1 EVALUATION COPY

Creating a Website with Google Sites

How to create pop-up menus

Remote Desktop Services

Android Basics. Xin Yang

Application Developer Guide

MicroStrategy Quick Guide: Creating Prompts ITU Data Mart Support Group, Reporting Services

Web Development Tutorials Web Design: WiX. Tutorial 1-3a

AIM Dashboard-User Documentation

for Sage 100 ERP Business Insights Overview Document

GroupWise to Outlook: How Do I?

Create a Simple Website. Intel Easy Steps Intel Corporation All rights reserved.

Creating Web Pages with Microsoft FrontPage

Android Mobile App Building Tutorial

Creating Dashboards. Intellicus Enterprise Reporting and BI Platform. Intellicus Technologies

Selection Manager: Quick Start Guide

MicroStrategy Quick Guide: Reconciliation Expense Report. Contents

Jordan Jozwiak November 13, 2011

Developing Rich Web Applications with Oracle ADF and Oracle WebCenter Portal

Redtail Integration. Establishing the Redtail Connection. 1. From the Applications dropdown, choose Setup.

Trigger. Perform this procedure when using the CRM Worklist. Helpful Hints

Android Application Development: Hands- On. Dr. Jogesh K. Muppala

Importing Data. Imports. File Sources. Importing Via Safari Download

IMPORTING FACILITIES TO CONTRACTS

Creating Personal Web Sites Using SharePoint Designer 2007

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

Table of Contents. Creating a Newsletter. Loading a Video or Slideshow. Distributing a Newsletter through Exact Target

Site Administrator Guide

Homework 9 Android App for Weather Forecast

Beginning Android Programming

Introduction to Microsoft Access 2003

PC Agent Quick Start. Open the Agent. Autonomy Connected Backup. Version 8.8. Revision 0

Introduction to Microsoft Word 2008

Egnyte App for Android Quick Start Guide

account multiple solutions

EM L18 Managing ios and Android Mobile Devices with Symantec Mobile Management Hands-On Lab

Setting Up groov Mobile Apps. Introduction. Setting Up groov Mobile Apps. Using the ios Mobile App

Add an E-Commerce Catalog to your Website

Student Microsoft Office 365

The LSUHSC N.O. Archive

Save and share documents in the cloud with OneDrive

Bank OnLine Commercial Administrator User s Guide

Managing Contacts in Outlook

Form Builder Manual. A brief overview of your website s Form Builder with screenshots.

MY EWU PORTAL FEATURES AND BENEFITS. Promotion of the Eastern brand name

Indiana Campaign Finance System Secure Site

Creating a Participants Mailing and/or Contact List:

Google Apps for Sharing Folders and Collecting Assignments

Transcription:

Chapter 9: Customize! Navigating with Tabs on a Tablet App

Objectives In this chapter, you learn to: Create an Android tablet project using a tab layout Code an XML layout with a TabHost control Display a TabWidget and FrameLayout within a TabHost Customize a GridView XML layout Develop a user interface that displays images in a GridView control Extend a TabActivity class 2

Objectives (continued) Display multiple classes as content within a tab layout Customize the ImageAdapter class for a GridView layout Open an Android Web browser in a tablet Customize a tab specification with TabSpec Add a TabSpec to a TabHost 3

Navigating with Tabs Tab interfaces have replaced traditional drop-down menus Tabs are used to: Show different topics within a single window Simplify Layout Eliminate the need for additional instructions Figures 9-1, 9-2, and 9-3 Bike and Barge Android tablet app, Second Tab displays tour information, Third tab opens a Web site 4

Navigating with Tabs (continued) Steps to complete the App: 1. Create a TabHost within the XML code that includes the TabWidget and FrameLayout. 2. Extend the TabActivity class. 3. Add the tab and GridView images needed for the project. 4. Create three different XML layouts for each of the tabs. a. Create the XML layout for the first tab to display a GridView control. b. Create the XML layout for the second tab to display TextView information. c. Create the XML layout for the third tab to display a Web site in a browser. 5. Create three different Activities; one for each tab. a. Code the first tab to display a GridView control. b. Code the second tab to display TextView information. c. Code the third tab to display a Web site in a browser. 6. Code the Main Activity to specify the TabSpec and launch the tabs. 7. Update the Android Manifest file. 5

Creating a Tab Layout for a Tablet An Android SDK provides a TabHost control so you can wrap multiple views in a single window The TabHost contains two distinct parts: A TabWidget for displaying the Tabs A FrameLayout for displaying the Tab content Each tab launches a separate Activity class All tabs are launched within a single Activity class 6

Creating a Tab Layout for a Tablet (continued) Figure 9-4 Anatomy of a TabHost control 7

The TabHost Layout TabHost requires a TabWidget and a FrameLayout within the XML layout code Use the default LinearLayout to position the TabWidget and the FrameLayout vertically TabHost, TabWidget, and FrameLayout must have ids assigned in the code Table 9-1 Tab control Android id Figure 9-6 TabHost XML code 8

The TabHost Layout (continued) Figure 9-8 TabWidget and FrameLayout within the TabHost 9

The TabHost Layout (continued) Figure 9-9 Graphical layout of TabHost 10

The TabHost Layout (continued) Extending the TabActivity Class A class named TabActivity makes it simple to display tabs within the app Figure 9-10 Main extends TabActivity 11

The TabHost Layout (continued) Adding the Tab and GridView Images Drag image files to the drawable-hdpi folder until a plus sign pointer appears Tab icons should be simple, flat shapes rather than 3D images Tab icons are typically sized at 72 X 72 pixels 12

The TabHost Layout (continued) Creating a GridView XML Layout for the First Tab A GridView control is similar to the Gallery control Displays objects in a two-dimensional, scrollable grid You specify: The number of columns The width of each column The space between columns 13

The TabHost Layout (continued) Figure 9-13 Custom GridView layout 14

The TabHost Layout (continued) Figure 9-14 First TextView control Figure 9-15 Second TextView control 15

The TabHost Layout (continued) Figure 9-16 Complete code for tab2.xml 16

The TabHost Layout (continued) Creating the XML Layout for the Third Tab Figure 9-17 tab3.xml 17

Coding the GridView Activity for the First Tab The First Tab of the GridView starts by displaying images Other two tabs available in the TabHost control This app requires four Java code Activity files Main.Java, Tab1.Java, Tab2.java, Tab3.java 18

Coding the GridView Activity for the First Tab (continued) Figure 9-18 Tab1.java class opens the tab1.xml layout Figure 9-19 GridView control is instantiated 19

Coding the GridView Activity for the First Tab (continued) Using a setadapter with an ImageAdapter setadapter provides a data model for the layout ImageAdapter binds the images to the GridView control Figure 9-20 Instance of the ImageAdapter class 20

Coding the GridView Activity for the First Tab (continued) Figure 9-21 ImageAdapter class 21

Coding the GridView Activity for the First Tab (continued) Customizing the ImageAdapter class The ImageAdapter class provides information to set up the GridView display Context is used to load and access resources for the app Figure 9-22 Context variable 22

Coding the GridView Activity for the First Tab (continued) Coding the getview Method The getview() method uses Context to create a new ImageView instance that is responsible for temporarily holding each image in the GridView control Figure 9-26 The getview method creates an instance of ImageView 23

Coding the GridView Activity for the First Tab (continued) Figure 9-27 Complete code for Tab1.java 24

Coding the Second Tab Java File Figure 9-28 Complete code for Tab2.java 25

Coding the Third Tab Java File to Display a Web Site Figure 9-30 Complete code for Tab3.java 26

Coding the TabHost Each tab must have a TabSpec, which specifies how the tab should appear The instance of the TabSpec calls the setindicator, which sets the tab button caption and supplies an icon image The setcontent method then indicates what is displayed in the tab content area 27

Coding the TabHost (continued) Figure 9-31 First tab is displayed with the Photos contents Figure 9-32 Second tab displays the Tour contents 28

Coding the TabHost (continued) Figure 9-33 Third tab displays the Web Site contents 29

Coding the TabHost (continued) Adding the TabSpec to the TabHost Figure 9-34 Complete code for Main.java 30

Updating the Android Manifest File Add references to all the tabs in the app Figure 9-35 Activities added to the Android Manifest 31

Running and Testing the Application Click Run on the menu bar Select Android Application from the dialog box Save all the files when prompted Unlock the emulator (if necessary) Test each tab to ensure it works as intended 32

Summary Use a TabHost control to create a tabbed interface similar to one used in a browser. The TabWidget displays the tabs, including labels and icons, and the FrameLayout displays the tab content. Specify the layout of a tabbed interface in the XML code. LinearLayout positions the controls vertically (FrameLayout below the TabWidget). Design a tabbed control in the main Java file by extending the TabActivity class instead of the Activity. A GridView control displays objects in a twodimensional, scrollable grid. 33

Summary (continued) A method to instantiates the custom ImageAdapter class ImageAdapter controls the layout of the GridView and connects the data sources from an array for display. Context is used to load and access resources for the application. To display the tabbed interface, you must fully code the Main.java class that extends TabActivity. 34

Summary (continued) Each tab in a tabbed interface must have a TabSpec statement, which creates an instance, that details tab content. The instance calls the setindicator method to set the tab button caption and supplies an icon image. The setcontent method indicates what is displayed in the tab content area. TabSpec must be added to the instance of the TabHost control and every tab change closes the previously opened tab and opens the selected tab. 35