SlideShare a Scribd company logo
© 2012 Marty Hall

Intents, Intent Filters,
and Invoking Activities:
Part III: Using Tabs
Originals of Slides and Source Code for Examples:
http://www.coreservlets.com/android-tutorial/
Customized Java EE Training: http://courses.coreservlets.com/
Java, JSF 2, PrimeFaces, Servlets, JSP, Ajax, jQuery, Spring, Hibernate, RESTful Web Services, Hadoop, Android.

Developed and taught by well-known author and developer. At public venues or onsite at your location.

© 2012 Marty Hall

For live Android training, please see courses
at http://courses.coreservlets.com/.
Taught by the author of Core Servlets and JSP, More
Servlets and JSP, and this Android tutorial. Available at
public venues, or customized versions can be held
on-site at your organization.
• Courses developed and taught by Marty Hall
– JSF 2, PrimeFaces, servlets/JSP, Ajax, jQuery, Android development, Java 6 or 7 programming, custom mix of topics
– Ajax courses can concentrate on 1EE Training: http://courses.coreservlets.com/several
Customized Java library (jQuery, Prototype/Scriptaculous, Ext-JS, Dojo, etc.) or survey

• Courses developed and taught by coreservlets.com experts (edited by Marty)

Java, JSF 2, PrimeFaces, Servlets, JSP, Ajax, jQuery, Spring,and RESTful Web Services Services, Hadoop, Android.
Hibernate, RESTful Web
– Spring, Hibernate/JPA, EJB3, GWT, Hadoop, SOAP-based
Contact hall@coreservlets.com for details
Developed and taught by well-known author and developer. At public venues or onsite at your location.
Topics in This Section
• Part I
– Invoking Activities by class name
– Defining dimensions in res/values
– Sending data via the “extras” Bundle

• Part II
– Invoking Activities with a URI
– Sending data via parameters in the URI

• Part III
– Invoking Activities with tabbed windows
– Defining two-image icons in res/drawable

5

© 2012 Marty Hall

Overview

Customized Java EE Training: http://courses.coreservlets.com/
Java, JSF 2, PrimeFaces, Servlets, JSP, Ajax, jQuery, Spring, Hibernate, RESTful Web Services, Hadoop, Android.

Developed and taught by well-known author and developer. At public venues or onsite at your location.
Summary of Options
• Invoke Activity by class name (Part I)
– Exactly one Activity can match
– New Activity must be in same project as original
– Can send data via an “extras” Bundle

• Invoke Activity by URI (Part II)
– More than one Activity could match
– New Activity need not be in the same project as original
– Can send data via URI parameters or “extras” Bundle

• Switch Activities via tabs (Part III)
– Can use class name or URI to specify Activity
– New Activity must be in same project as original
– Can send data via URI parameters or “extras” Bundle
7

© 2012 Marty Hall

Invoking Activities with
Tabbed Windows
Customized Java EE Training: http://courses.coreservlets.com/
Java, JSF 2, PrimeFaces, Servlets, JSP, Ajax, jQuery, Spring, Hibernate, RESTful Web Services, Hadoop, Android.

Developed and taught by well-known author and developer. At public venues or onsite at your location.
Summary
• Idea
– Make tabbed windows. Each tab invokes a different Activity,
or an Activity with different data.
• Can use either specific-class approach or URI approach
• Can send data either with an extras Bundle or in URI
• Tab window Activity and new Activities must be in same project
– Due to security reasons

• Syntax
– Java
• Extends TabActivity. Uses TabHost and TabSpec
– Details on next slide

– XML (AndroidManifest.xml)
• Same as shown earlier
9

Using TabActivity: Outline
public class SomeActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Resources resources = getResources();
TabHost host = getTabHost();
Intent intent1= ...;
Drawable tabIcon =
resources.getDrawable(R.drawable.icon_name);
TabSpec tab1Spec =
host.newTabSpec("Tab One")
.setIndicator("Some Text", tabIcon)
.setContent(intent1);
host.addTab(tab1Spec);
// Repeat for other tabs
}
Note that the setter methods for TabSpec return the TabSpec so that you can do chained assignments.
}
Note also that there is no layout file when using this approach.
10
Defining Tab Icons
• Idea
– Although it is legal to call setIndicator(someString), the
resultant tab looks bad because of blank space at top. So,
more common to do setIndicator(someString, someIcon).
• You can also do setIndicator(someView) for fancy tabs

• Icon option 1
– Use a single image for the icon
• Same image used when the tab is or is not selected

• Icon option 2
– Use 2 similar but differently colored images for the icon
• One for when selected, one for when not

11

Option 1: A Single Image
• Pros
– Simpler
– Text color and background color of the tab already
change on selection, so not confusing if icon stays same.

• Cons
– Doesn’t look quite as good as with two images

• Approach
– Put image file in res/drawable/some_icon.png
– Refer to image with
• Drawable tabIcon =
resources.getDrawable(R.drawable.some_icon);

– Put icon in tab label with
12

• tabSpec.setIndicator("Some Text", tabIcon);
Option 2: Two Images
(Normal and Selected)
• Pros
– Looks better

• Cons
– More work

• Approach
– Put image files in
• res/drawable/some_icon_normal.png
and
• res/drawable/some_icon_selected.png

– Make XML file (next page)
• res/drawable/some_icon.xml

– Refer to XML file with
• Drawable tabIcon =
resources.getDrawable(R.drawable.some_icon);

– Put icon in tab label with
• tabSpec.setIndicator("Some Text", tabIcon);
13

XML Code for Dual-Image Icon
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://...">
<!-- When tab selected, use some_icon_selected.png -->
<item android:drawable="@drawable/some_icon_selected"
android:state_selected="true" />
<!-- When tab not selected, use some_icon_normal.png -->
<item android:drawable="@drawable/some_icon_normal" />
</selector>

The file names of the two images are arbitrary. They need not end in _selected and _normal, although
this can be a useful convention so that you know what the images are for.
14
© 2012 Marty Hall

Example:
Invoking Loan Calculator
(Each Tab Sends
Different Data)
Customized Java EE Training: http://courses.coreservlets.com/
Java, JSF 2, PrimeFaces, Servlets, JSP, Ajax, jQuery, Spring, Hibernate, RESTful Web Services, Hadoop, Android.

Developed and taught by well-known author and developer. At public venues or onsite at your location.

Example: Overview
• Initial Activity
– Has tabs that, when pressed, invoke the
loan calculator with different data
• Activity specified either with class name or URI
– But either way, initial Activity must be in same project as new one

• Data sent via either in extras Bundle or in URI

• Approach
– Intents and data created in same way as before
– Intent associated with tab via tabHost.setContent
– Put entry for LoanCalculatorActivity in manifest
• Same as shown previously

16
XML: Icon File
(res/drawable/calculator.xml)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Calculator images from http://www.fatcow.com/free-icons -->
<!-- When selected, use white -->
<item android:drawable="@drawable/calculator_white"
android:state_selected="true" />
<!-- When not selected, use black-->
<item android:drawable="@drawable/calculator_black" />
</selector>

17

XML: Manifest File
Action Declaration
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.coreservlets.intentfilter1"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon"
android:label="@string/app_name">
... <!-- Declaration for IntentFilter1Activity shown earlier -->
<activity android:name=".LoanCalculatorActivity"
android:label="@string/loan_calculator_app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="loan" android:host="coreservlets.com" />
</intent-filter>
</activity>
...
</application>
Unchanged from previous examples.
</manifest>

18
Java
(TabbedActivity: Tab 1)
public class TabbedActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Resources resources = getResources();
TabHost host = getTabHost();
Intent intent1 =
new Intent(this, LoanCalculatorActivity.class);
Bundle loanBundle1 =
LoanBundler.makeLoanInfoBundle(100000, 7.5, 120);
intent1.putExtras(loanBundle1);
Drawable tabIcon =
resources.getDrawable(R.drawable.calculator);
TabSpec tab1Spec = host.newTabSpec("Tab One")
.setIndicator("10 Year", tabIcon)
.setContent(intent1);
host.addTab(tab1Spec);

19

This first tab uses an Intent that specifies the Activity by class name.
It sends data via an extras Bundle. Reminder: there is no layout file when using TabActivity.

Java
(TabbedActivity: Tab 2)
Uri uriTwentyYear =
Uri.parse("loan://coreservlets.com/calc");
Intent intent2 =
new Intent(Intent.ACTION_VIEW, uriTwentyYear);
Bundle loanBundle2 =
LoanBundler.makeLoanInfoBundle(100000, 7.5, 240);
intent2.putExtras(loanBundle2);
tabIcon = resources.getDrawable(R.drawable.calculator);
TabSpec tab2Spec = host.newTabSpec("Tab Two")
.setIndicator("20 Year", tabIcon)
.setContent(intent2);
host.addTab(tab2Spec);

20

This second tab uses an Intent that specifies the Activity with a URI.
It sends data via an extras Bundle.
Java
(TabbedActivity: Tab 3)
String baseAddress = "loan://coreservlets.com/calc";
String address =
String.format("%s?%s&%s&%s",
baseAddress,
"loanAmount=100000",
"annualInterestRateInPercent=7.5",
"loanPeriodInMonths=360");
Uri uriThirtyYear = Uri.parse(address);
Intent intent3 =
new Intent(Intent.ACTION_VIEW, uriThirtyYear);
tabIcon = resources.getDrawable(R.drawable.calculator);
TabSpec tab3Spec = host.newTabSpec("Tab Three")
.setIndicator("30 Year", tabIcon)
.setContent(intent3);
host.addTab(tab3Spec);

21

This second tab uses an Intent that specifies the Activity with a URI.
It sends data via parameters embedded in the URI.

Example: Results

22
© 2012 Marty Hall

Wrap-Up
Customized Java EE Training: http://courses.coreservlets.com/
Java, JSF 2, PrimeFaces, Servlets, JSP, Ajax, jQuery, Spring, Hibernate, RESTful Web Services, Hadoop, Android.

Developed and taught by well-known author and developer. At public venues or onsite at your location.

Summary
• Java (extends TabActivity)
TabHost host = getTabHost();
Intent intent1= ...; // Refers to Activity in same project
Drawable tabIcon = resources.getDrawable(R.drawable.some_icon);
TabSpec tab1Spec = host.newTabSpec("Tab One")
.setIndicator("Some Text", tabIcon)
.setContent(intent1);
host.addTab(tab1Spec);
// Repeat for other tabs

• Icon (res/drawable/some_icon.xml)

24

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://...">
<item android:drawable="@drawable/some_icon_selected"
android:state_selected="true" />
<item android:drawable="@drawable/some_icon_normal" />
</selector>
© 2012 Marty Hall

Questions?
JSF 2, PrimeFaces, Java 7, Ajax, jQuery, Hadoop, RESTful Web Services, Android, Spring, Hibernate, Servlets, JSP, GWT, and other Java EE training.

Customized Java EE Training: http://courses.coreservlets.com/
Java, JSF 2, PrimeFaces, Servlets, JSP, Ajax, jQuery, Spring, Hibernate, RESTful Web Services, Hadoop, Android.

Developed and taught by well-known author and developer. At public venues or onsite at your location.
Ad

More Related Content

What's hot (20)

Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
Oscar Merida
 
Advanced moduledevelopment d6_slideshare
Advanced moduledevelopment d6_slideshareAdvanced moduledevelopment d6_slideshare
Advanced moduledevelopment d6_slideshare
Opevel
 
[2015/2016] Local data storage for web-based mobile apps
[2015/2016] Local data storage for web-based mobile apps[2015/2016] Local data storage for web-based mobile apps
[2015/2016] Local data storage for web-based mobile apps
Ivano Malavolta
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSCreating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJS
Gunnar Hillert
 
Advanced #6 clean architecture
Advanced #6  clean architectureAdvanced #6  clean architecture
Advanced #6 clean architecture
Vitali Pekelis
 
The Spring Update
The Spring UpdateThe Spring Update
The Spring Update
Gunnar Hillert
 
Actionview
ActionviewActionview
Actionview
Amal Subhash
 
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your ApplicationsThe Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
balassaitis
 
Customizing the Document Library
Customizing the Document LibraryCustomizing the Document Library
Customizing the Document Library
Alfresco Software
 
Lift Framework
Lift FrameworkLift Framework
Lift Framework
Jeffrey Groneberg
 
Working with Hive Analytics
Working with Hive AnalyticsWorking with Hive Analytics
Working with Hive Analytics
Manish Chopra
 
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
SPTechCon
 
Migrate to Drupal 8
Migrate to Drupal 8Migrate to Drupal 8
Migrate to Drupal 8
Claudiu Cristea
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling Rewriter
Justin Edelson
 
04 integrate entityframework
04 integrate entityframework04 integrate entityframework
04 integrate entityframework
Erhwen Kuo
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
Aneega
 
jQuery
jQueryjQuery
jQuery
Ivano Malavolta
 
Core Data with Swift 3.0
Core Data with Swift 3.0Core Data with Swift 3.0
Core Data with Swift 3.0
Korhan Bircan
 
What is WebDAV - uploaded by Murali Krishna Nookella
What is WebDAV - uploaded by Murali Krishna NookellaWhat is WebDAV - uploaded by Murali Krishna Nookella
What is WebDAV - uploaded by Murali Krishna Nookella
muralikrishnanookella
 
Java EE revisits design patterns
Java EE revisits design patternsJava EE revisits design patterns
Java EE revisits design patterns
Alex Theedom
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
Oscar Merida
 
Advanced moduledevelopment d6_slideshare
Advanced moduledevelopment d6_slideshareAdvanced moduledevelopment d6_slideshare
Advanced moduledevelopment d6_slideshare
Opevel
 
[2015/2016] Local data storage for web-based mobile apps
[2015/2016] Local data storage for web-based mobile apps[2015/2016] Local data storage for web-based mobile apps
[2015/2016] Local data storage for web-based mobile apps
Ivano Malavolta
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSCreating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJS
Gunnar Hillert
 
Advanced #6 clean architecture
Advanced #6  clean architectureAdvanced #6  clean architecture
Advanced #6 clean architecture
Vitali Pekelis
 
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your ApplicationsThe Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
balassaitis
 
Customizing the Document Library
Customizing the Document LibraryCustomizing the Document Library
Customizing the Document Library
Alfresco Software
 
Working with Hive Analytics
Working with Hive AnalyticsWorking with Hive Analytics
Working with Hive Analytics
Manish Chopra
 
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
SPTechCon
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling Rewriter
Justin Edelson
 
04 integrate entityframework
04 integrate entityframework04 integrate entityframework
04 integrate entityframework
Erhwen Kuo
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
Aneega
 
Core Data with Swift 3.0
Core Data with Swift 3.0Core Data with Swift 3.0
Core Data with Swift 3.0
Korhan Bircan
 
What is WebDAV - uploaded by Murali Krishna Nookella
What is WebDAV - uploaded by Murali Krishna NookellaWhat is WebDAV - uploaded by Murali Krishna Nookella
What is WebDAV - uploaded by Murali Krishna Nookella
muralikrishnanookella
 
Java EE revisits design patterns
Java EE revisits design patternsJava EE revisits design patterns
Java EE revisits design patterns
Alex Theedom
 

Viewers also liked (7)

License
LicenseLicense
License
rahmaliani
 
D math graph
D math graphD math graph
D math graph
Budi Irmawati
 
Dj tïesto
Dj tïestoDj tïesto
Dj tïesto
fre792
 
Dj tïesto
Dj tïestoDj tïesto
Dj tïesto
fre792
 
10 consulting notes_forco-pa_analysts
10 consulting notes_forco-pa_analysts10 consulting notes_forco-pa_analysts
10 consulting notes_forco-pa_analysts
Sreenivas Kumar
 
استخدام الرسوم المتحركة الناطقة فى تنمية مهارتي الاستماع والتحدث لدى تلاميذ ا...
استخدام الرسوم المتحركة الناطقة فى تنمية مهارتي الاستماع والتحدث لدى تلاميذ ا...استخدام الرسوم المتحركة الناطقة فى تنمية مهارتي الاستماع والتحدث لدى تلاميذ ا...
استخدام الرسوم المتحركة الناطقة فى تنمية مهارتي الاستماع والتحدث لدى تلاميذ ا...
eman3460
 
I order1
I order1I order1
I order1
Sreenivas Kumar
 
Dj tïesto
Dj tïestoDj tïesto
Dj tïesto
fre792
 
Dj tïesto
Dj tïestoDj tïesto
Dj tïesto
fre792
 
10 consulting notes_forco-pa_analysts
10 consulting notes_forco-pa_analysts10 consulting notes_forco-pa_analysts
10 consulting notes_forco-pa_analysts
Sreenivas Kumar
 
استخدام الرسوم المتحركة الناطقة فى تنمية مهارتي الاستماع والتحدث لدى تلاميذ ا...
استخدام الرسوم المتحركة الناطقة فى تنمية مهارتي الاستماع والتحدث لدى تلاميذ ا...استخدام الرسوم المتحركة الناطقة فى تنمية مهارتي الاستماع والتحدث لدى تلاميذ ا...
استخدام الرسوم المتحركة الناطقة فى تنمية مهارتي الاستماع والتحدث لدى تلاميذ ا...
eman3460
 
Ad

Similar to Android intents-3 www.j2program.blogspot.com (20)

Lec005 android start_program
Lec005 android start_programLec005 android start_program
Lec005 android start_program
Eyad Almasri
 
Android layouts
Android layoutsAndroid layouts
Android layouts
Jeffrey Quevedo
 
Json generation
Json generationJson generation
Json generation
Aravindharamanan S
 
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Arun Gupta
 
Writing HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAE
Ron Reiter
 
JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011
Arun Gupta
 
Ajax Tags Advanced
Ajax Tags AdvancedAjax Tags Advanced
Ajax Tags Advanced
AkramWaseem
 
Web applications with Catalyst
Web applications with CatalystWeb applications with Catalyst
Web applications with Catalyst
svilen.ivanov
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
SPTechCon
 
Web works hol
Web works holWeb works hol
Web works hol
momoahmedabad
 
Prototyping applications with heroku and elasticsearch
 Prototyping applications with heroku and elasticsearch Prototyping applications with heroku and elasticsearch
Prototyping applications with heroku and elasticsearch
protofy
 
Intro lift
Intro liftIntro lift
Intro lift
Knoldus Inc.
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 
JQuery-Tutorial
 JQuery-Tutorial JQuery-Tutorial
JQuery-Tutorial
tutorialsruby
 
Microsoft PowerPoint - &lt;b>jQuery&lt;/b>-3-UI.pptx
Microsoft PowerPoint - &lt;b>jQuery&lt;/b>-3-UI.pptxMicrosoft PowerPoint - &lt;b>jQuery&lt;/b>-3-UI.pptx
Microsoft PowerPoint - &lt;b>jQuery&lt;/b>-3-UI.pptx
tutorialsruby
 
jQuery-3-UI
jQuery-3-UIjQuery-3-UI
jQuery-3-UI
guestcf600a
 
jQuery-3-UI
jQuery-3-UIjQuery-3-UI
jQuery-3-UI
guestcf600a
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Alek Davis
 
Intro to appcelerator
Intro to appceleratorIntro to appcelerator
Intro to appcelerator
Mohab El-Shishtawy
 
React native
React nativeReact native
React native
Mohammed El Rafie Tarabay
 
Lec005 android start_program
Lec005 android start_programLec005 android start_program
Lec005 android start_program
Eyad Almasri
 
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Arun Gupta
 
Writing HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAE
Ron Reiter
 
JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011
Arun Gupta
 
Ajax Tags Advanced
Ajax Tags AdvancedAjax Tags Advanced
Ajax Tags Advanced
AkramWaseem
 
Web applications with Catalyst
Web applications with CatalystWeb applications with Catalyst
Web applications with Catalyst
svilen.ivanov
 
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
SPTechCon
 
Prototyping applications with heroku and elasticsearch
 Prototyping applications with heroku and elasticsearch Prototyping applications with heroku and elasticsearch
Prototyping applications with heroku and elasticsearch
protofy
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 
Microsoft PowerPoint - &lt;b>jQuery&lt;/b>-3-UI.pptx
Microsoft PowerPoint - &lt;b>jQuery&lt;/b>-3-UI.pptxMicrosoft PowerPoint - &lt;b>jQuery&lt;/b>-3-UI.pptx
Microsoft PowerPoint - &lt;b>jQuery&lt;/b>-3-UI.pptx
tutorialsruby
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Alek Davis
 
Ad

Recently uploaded (20)

Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Political History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptxPolitical History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 

Android intents-3 www.j2program.blogspot.com

  • 1. © 2012 Marty Hall Intents, Intent Filters, and Invoking Activities: Part III: Using Tabs Originals of Slides and Source Code for Examples: http://www.coreservlets.com/android-tutorial/ Customized Java EE Training: http://courses.coreservlets.com/ Java, JSF 2, PrimeFaces, Servlets, JSP, Ajax, jQuery, Spring, Hibernate, RESTful Web Services, Hadoop, Android. Developed and taught by well-known author and developer. At public venues or onsite at your location. © 2012 Marty Hall For live Android training, please see courses at http://courses.coreservlets.com/. Taught by the author of Core Servlets and JSP, More Servlets and JSP, and this Android tutorial. Available at public venues, or customized versions can be held on-site at your organization. • Courses developed and taught by Marty Hall – JSF 2, PrimeFaces, servlets/JSP, Ajax, jQuery, Android development, Java 6 or 7 programming, custom mix of topics – Ajax courses can concentrate on 1EE Training: http://courses.coreservlets.com/several Customized Java library (jQuery, Prototype/Scriptaculous, Ext-JS, Dojo, etc.) or survey • Courses developed and taught by coreservlets.com experts (edited by Marty) Java, JSF 2, PrimeFaces, Servlets, JSP, Ajax, jQuery, Spring,and RESTful Web Services Services, Hadoop, Android. Hibernate, RESTful Web – Spring, Hibernate/JPA, EJB3, GWT, Hadoop, SOAP-based Contact [email protected] for details Developed and taught by well-known author and developer. At public venues or onsite at your location.
  • 2. Topics in This Section • Part I – Invoking Activities by class name – Defining dimensions in res/values – Sending data via the “extras” Bundle • Part II – Invoking Activities with a URI – Sending data via parameters in the URI • Part III – Invoking Activities with tabbed windows – Defining two-image icons in res/drawable 5 © 2012 Marty Hall Overview Customized Java EE Training: http://courses.coreservlets.com/ Java, JSF 2, PrimeFaces, Servlets, JSP, Ajax, jQuery, Spring, Hibernate, RESTful Web Services, Hadoop, Android. Developed and taught by well-known author and developer. At public venues or onsite at your location.
  • 3. Summary of Options • Invoke Activity by class name (Part I) – Exactly one Activity can match – New Activity must be in same project as original – Can send data via an “extras” Bundle • Invoke Activity by URI (Part II) – More than one Activity could match – New Activity need not be in the same project as original – Can send data via URI parameters or “extras” Bundle • Switch Activities via tabs (Part III) – Can use class name or URI to specify Activity – New Activity must be in same project as original – Can send data via URI parameters or “extras” Bundle 7 © 2012 Marty Hall Invoking Activities with Tabbed Windows Customized Java EE Training: http://courses.coreservlets.com/ Java, JSF 2, PrimeFaces, Servlets, JSP, Ajax, jQuery, Spring, Hibernate, RESTful Web Services, Hadoop, Android. Developed and taught by well-known author and developer. At public venues or onsite at your location.
  • 4. Summary • Idea – Make tabbed windows. Each tab invokes a different Activity, or an Activity with different data. • Can use either specific-class approach or URI approach • Can send data either with an extras Bundle or in URI • Tab window Activity and new Activities must be in same project – Due to security reasons • Syntax – Java • Extends TabActivity. Uses TabHost and TabSpec – Details on next slide – XML (AndroidManifest.xml) • Same as shown earlier 9 Using TabActivity: Outline public class SomeActivity extends TabActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Resources resources = getResources(); TabHost host = getTabHost(); Intent intent1= ...; Drawable tabIcon = resources.getDrawable(R.drawable.icon_name); TabSpec tab1Spec = host.newTabSpec("Tab One") .setIndicator("Some Text", tabIcon) .setContent(intent1); host.addTab(tab1Spec); // Repeat for other tabs } Note that the setter methods for TabSpec return the TabSpec so that you can do chained assignments. } Note also that there is no layout file when using this approach. 10
  • 5. Defining Tab Icons • Idea – Although it is legal to call setIndicator(someString), the resultant tab looks bad because of blank space at top. So, more common to do setIndicator(someString, someIcon). • You can also do setIndicator(someView) for fancy tabs • Icon option 1 – Use a single image for the icon • Same image used when the tab is or is not selected • Icon option 2 – Use 2 similar but differently colored images for the icon • One for when selected, one for when not 11 Option 1: A Single Image • Pros – Simpler – Text color and background color of the tab already change on selection, so not confusing if icon stays same. • Cons – Doesn’t look quite as good as with two images • Approach – Put image file in res/drawable/some_icon.png – Refer to image with • Drawable tabIcon = resources.getDrawable(R.drawable.some_icon); – Put icon in tab label with 12 • tabSpec.setIndicator("Some Text", tabIcon);
  • 6. Option 2: Two Images (Normal and Selected) • Pros – Looks better • Cons – More work • Approach – Put image files in • res/drawable/some_icon_normal.png and • res/drawable/some_icon_selected.png – Make XML file (next page) • res/drawable/some_icon.xml – Refer to XML file with • Drawable tabIcon = resources.getDrawable(R.drawable.some_icon); – Put icon in tab label with • tabSpec.setIndicator("Some Text", tabIcon); 13 XML Code for Dual-Image Icon <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://..."> <!-- When tab selected, use some_icon_selected.png --> <item android:drawable="@drawable/some_icon_selected" android:state_selected="true" /> <!-- When tab not selected, use some_icon_normal.png --> <item android:drawable="@drawable/some_icon_normal" /> </selector> The file names of the two images are arbitrary. They need not end in _selected and _normal, although this can be a useful convention so that you know what the images are for. 14
  • 7. © 2012 Marty Hall Example: Invoking Loan Calculator (Each Tab Sends Different Data) Customized Java EE Training: http://courses.coreservlets.com/ Java, JSF 2, PrimeFaces, Servlets, JSP, Ajax, jQuery, Spring, Hibernate, RESTful Web Services, Hadoop, Android. Developed and taught by well-known author and developer. At public venues or onsite at your location. Example: Overview • Initial Activity – Has tabs that, when pressed, invoke the loan calculator with different data • Activity specified either with class name or URI – But either way, initial Activity must be in same project as new one • Data sent via either in extras Bundle or in URI • Approach – Intents and data created in same way as before – Intent associated with tab via tabHost.setContent – Put entry for LoanCalculatorActivity in manifest • Same as shown previously 16
  • 8. XML: Icon File (res/drawable/calculator.xml) <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Calculator images from http://www.fatcow.com/free-icons --> <!-- When selected, use white --> <item android:drawable="@drawable/calculator_white" android:state_selected="true" /> <!-- When not selected, use black--> <item android:drawable="@drawable/calculator_black" /> </selector> 17 XML: Manifest File Action Declaration <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.coreservlets.intentfilter1" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> ... <!-- Declaration for IntentFilter1Activity shown earlier --> <activity android:name=".LoanCalculatorActivity" android:label="@string/loan_calculator_app_name"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="loan" android:host="coreservlets.com" /> </intent-filter> </activity> ... </application> Unchanged from previous examples. </manifest> 18
  • 9. Java (TabbedActivity: Tab 1) public class TabbedActivity extends TabActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Resources resources = getResources(); TabHost host = getTabHost(); Intent intent1 = new Intent(this, LoanCalculatorActivity.class); Bundle loanBundle1 = LoanBundler.makeLoanInfoBundle(100000, 7.5, 120); intent1.putExtras(loanBundle1); Drawable tabIcon = resources.getDrawable(R.drawable.calculator); TabSpec tab1Spec = host.newTabSpec("Tab One") .setIndicator("10 Year", tabIcon) .setContent(intent1); host.addTab(tab1Spec); 19 This first tab uses an Intent that specifies the Activity by class name. It sends data via an extras Bundle. Reminder: there is no layout file when using TabActivity. Java (TabbedActivity: Tab 2) Uri uriTwentyYear = Uri.parse("loan://coreservlets.com/calc"); Intent intent2 = new Intent(Intent.ACTION_VIEW, uriTwentyYear); Bundle loanBundle2 = LoanBundler.makeLoanInfoBundle(100000, 7.5, 240); intent2.putExtras(loanBundle2); tabIcon = resources.getDrawable(R.drawable.calculator); TabSpec tab2Spec = host.newTabSpec("Tab Two") .setIndicator("20 Year", tabIcon) .setContent(intent2); host.addTab(tab2Spec); 20 This second tab uses an Intent that specifies the Activity with a URI. It sends data via an extras Bundle.
  • 10. Java (TabbedActivity: Tab 3) String baseAddress = "loan://coreservlets.com/calc"; String address = String.format("%s?%s&%s&%s", baseAddress, "loanAmount=100000", "annualInterestRateInPercent=7.5", "loanPeriodInMonths=360"); Uri uriThirtyYear = Uri.parse(address); Intent intent3 = new Intent(Intent.ACTION_VIEW, uriThirtyYear); tabIcon = resources.getDrawable(R.drawable.calculator); TabSpec tab3Spec = host.newTabSpec("Tab Three") .setIndicator("30 Year", tabIcon) .setContent(intent3); host.addTab(tab3Spec); 21 This second tab uses an Intent that specifies the Activity with a URI. It sends data via parameters embedded in the URI. Example: Results 22
  • 11. © 2012 Marty Hall Wrap-Up Customized Java EE Training: http://courses.coreservlets.com/ Java, JSF 2, PrimeFaces, Servlets, JSP, Ajax, jQuery, Spring, Hibernate, RESTful Web Services, Hadoop, Android. Developed and taught by well-known author and developer. At public venues or onsite at your location. Summary • Java (extends TabActivity) TabHost host = getTabHost(); Intent intent1= ...; // Refers to Activity in same project Drawable tabIcon = resources.getDrawable(R.drawable.some_icon); TabSpec tab1Spec = host.newTabSpec("Tab One") .setIndicator("Some Text", tabIcon) .setContent(intent1); host.addTab(tab1Spec); // Repeat for other tabs • Icon (res/drawable/some_icon.xml) 24 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://..."> <item android:drawable="@drawable/some_icon_selected" android:state_selected="true" /> <item android:drawable="@drawable/some_icon_normal" /> </selector>
  • 12. © 2012 Marty Hall Questions? JSF 2, PrimeFaces, Java 7, Ajax, jQuery, Hadoop, RESTful Web Services, Android, Spring, Hibernate, Servlets, JSP, GWT, and other Java EE training. Customized Java EE Training: http://courses.coreservlets.com/ Java, JSF 2, PrimeFaces, Servlets, JSP, Ajax, jQuery, Spring, Hibernate, RESTful Web Services, Hadoop, Android. Developed and taught by well-known author and developer. At public venues or onsite at your location.