SlideShare a Scribd company logo
1 of 32
Download to read offline
Android Programming Basics
Agenda
Basic program structure
Java-based layout
XML-based layout
Eclipse ADT visual layout editor
Hybrid layout
Project structure summary
General Structure (Common to All Approaches)
Three Main Approaches
 • Java-based
 – Use Java to define Strings, lay out window, create GUI controls, and assign
event handlers. Like Swing programming.
 • XML-based
 – Use XML files to define Strings, lay out window, create GUI controls, and
assign event handlers. The Java method will read the layout from XML file
and pass it to setContentView.
 • Hybrid
 – Use an XML file to define Strings, lay out window and create GUI controls.
Use Java to assign event handlers.
 • Examples in this tutorial section
 – Button that says “Show Greeting”. Small popup message appears when
button is pressed.
 – Implemented each of the three ways.
Java-Based Approach: Template
XML-Based Approach: Template
Hybrid Approach: Template
Java-Based Layout
Big Idea
 • Approach
 – Use Java to define Strings, lay out window, create GUI controls, and assign
event handlers.
 • Advantages
 – Familiar to Java desktop developers. Like approach used for Swing, SWT,
and AWT.
 – Good for layouts that are dynamic (i.e., that change based on program logic).
 • Disadvantages
 – Harder to maintain (arguable, but general consensus)
 – Works poorly with I18N
 – Not generally recommended except for dynamic layouts
 • But still acceptable for App Store. Whatever works best for your
programmers and your app. No code police.
Code (Main Method)
Code (Event Handler Method)
Results on Emulator
Results on Physical Phone
• Reminder
– Configured phone (once only)
– Shut down emulator, plugged in phone
– R-clicked project, Run As->Android Application
XML-Based Layout
Big Idea
 • Approach
 – Use XML files to define Strings, lay out window, create GUI controls, and assign event
handlers.
 • Define layout and controls in res/layout/main.xml
 • Define Strings in res/values/strings.xml
 • Advantages
 – Easier to maintain
 – Works well with I18N
 – Can use visual layout editor in Eclipse
 – Standard/recommended approach (along with hybrid)
 • Disadvantages
 – Works poorly for dynamic layouts
More Details
 • res/layout/main.xml
 – Define layout and controls with XML description
 • <LinearLayout …>Define controls</LinearLayout>
 – Refer to strings (from strings.xml) with @string/string_name
 – Assign event handler with android:onClick
 • res/values/strings.xml
 – Define strings used in GUI or that might change with I18N
 • Java code
 – Refer to layout with R.layout.main (res/layout/main.xml)
 – Refer to strings with getString(R.string.string_name)
 – Refer to controls with findViewById(R.id.some_id)
 • More info
 – http://developer.android.com/guide/topics/ui/declaring-layout.html
Project Layout
Code (res/layout/main.xml)
Code (res/values/strings.xml)
Code (Java)
Results
Eclipse ADT
Visual Layout Editor
 • Invoking
 – When editing main.xml, click Graphical Layout
 • Features
 – Can interactively change layout attributes (vertical/horizontal, fill
 characteristics, etc.)
 – Can drag from palette of available GUI controls
 – Can interactively set control characteristics (colors, fill, event handler, etc.)
 – Shows visual preview
 • Warning
 – Although visual editor is very useful, you should still manually edit XML to
fix indentation, order of attributes, use of obsolete attribute names (fill_parent
instead of match_parent), and other stylistic things.
Eclipse Visual Layout Editor
Hybrid Layout
Big Idea
 • Approach
 – Use XML files to define Strings, lay out window, and create
GUI controls.
 – Use Java to assign event handlers.
 • Advantages
 – Mostly same as XML-based approach
 – But, since event handler needs to be edited by Java programmer
anyhow, often makes more sense to assign it programmatically as
well.
 • Disadvantages
 – Works poorly for dynamic layouts
Code (res/layout/main.xml)
Code (res/values/strings.xml)
Code (Java)
Results
Project Layout
Summary
Questions?

More Related Content

Viewers also liked

Introduction to Android and Android Studio
Introduction to Android and Android StudioIntroduction to Android and Android Studio
Introduction to Android and Android StudioSuyash Srijan
 
Being Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentBeing Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentReto Meier
 
What is Android OS in ppt ?
What is Android OS in ppt ? What is Android OS in ppt ?
What is Android OS in ppt ? SoonTips.com
 
Android OS Presentation
Android OS PresentationAndroid OS Presentation
Android OS Presentationhession25819
 
Android Development: The Basics
Android Development: The BasicsAndroid Development: The Basics
Android Development: The BasicsMike Desjardins
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with NougatOpersys inc.
 
Presentation on Android operating system
Presentation on Android operating systemPresentation on Android operating system
Presentation on Android operating systemSalma Begum
 
Smart Attendance Management System Using Android WIFI Technology
Smart Attendance Management System Using Android WIFI TechnologySmart Attendance Management System Using Android WIFI Technology
Smart Attendance Management System Using Android WIFI TechnologySukanta Biswas
 
Android workshop | LoopTalks
Android workshop | LoopTalksAndroid workshop | LoopTalks
Android workshop | LoopTalksLoopTalks
 

Viewers also liked (13)

Android studio
Android studioAndroid studio
Android studio
 
Android Workshop PPT
Android Workshop PPTAndroid Workshop PPT
Android Workshop PPT
 
Introduction to Android and Android Studio
Introduction to Android and Android StudioIntroduction to Android and Android Studio
Introduction to Android and Android Studio
 
Being Epic: Best Practices for Android Development
Being Epic: Best Practices for Android DevelopmentBeing Epic: Best Practices for Android Development
Being Epic: Best Practices for Android Development
 
What is Android OS in ppt ?
What is Android OS in ppt ? What is Android OS in ppt ?
What is Android OS in ppt ?
 
Android OS Presentation
Android OS PresentationAndroid OS Presentation
Android OS Presentation
 
Android Development: The Basics
Android Development: The BasicsAndroid Development: The Basics
Android Development: The Basics
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with Nougat
 
Android ppt
Android pptAndroid ppt
Android ppt
 
Presentation on Android operating system
Presentation on Android operating systemPresentation on Android operating system
Presentation on Android operating system
 
Smart Attendance Management System Using Android WIFI Technology
Smart Attendance Management System Using Android WIFI TechnologySmart Attendance Management System Using Android WIFI Technology
Smart Attendance Management System Using Android WIFI Technology
 
Android workshop | LoopTalks
Android workshop | LoopTalksAndroid workshop | LoopTalks
Android workshop | LoopTalks
 
Android ppt
Android ppt Android ppt
Android ppt
 

Similar to 01 06 - android programming basics

Lec005 android start_program
Lec005 android start_programLec005 android start_program
Lec005 android start_programEyad Almasri
 
Designing and implementing_android_uis_for_phones_and_tablets
Designing and implementing_android_uis_for_phones_and_tabletsDesigning and implementing_android_uis_for_phones_and_tablets
Designing and implementing_android_uis_for_phones_and_tabletsTeddy Koornia
 
Lecture 02: Android Layouts.pptx
Lecture 02: Android Layouts.pptxLecture 02: Android Layouts.pptx
Lecture 02: Android Layouts.pptxYousef Alamir
 
Ad103 - Have it Your Way: Extending IBM Lotus Domino Designer
Ad103 - Have it Your Way: Extending IBM Lotus Domino DesignerAd103 - Have it Your Way: Extending IBM Lotus Domino Designer
Ad103 - Have it Your Way: Extending IBM Lotus Domino Designerddrschiw
 
Implementing a Symfony Based CMS in a Publishing Company
Implementing a Symfony Based CMS in a Publishing CompanyImplementing a Symfony Based CMS in a Publishing Company
Implementing a Symfony Based CMS in a Publishing CompanyMarcos Labad
 
mobile application development -unit-3-
mobile application development  -unit-3-mobile application development  -unit-3-
mobile application development -unit-3-TejamFandat
 
Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart JfokusLars Vogel
 
RomaFramework Tutorial Basics
RomaFramework Tutorial BasicsRomaFramework Tutorial Basics
RomaFramework Tutorial BasicsLuca Garulli
 
Android development orientation for starters v2
Android development orientation for starters v2Android development orientation for starters v2
Android development orientation for starters v2Joemarie Amparo
 
Lavacon 2014 responsive design in your hat
Lavacon 2014   responsive design in your hatLavacon 2014   responsive design in your hat
Lavacon 2014 responsive design in your hatNeil Perlin
 
Android training day 2
Android training day 2Android training day 2
Android training day 2Vivek Bhusal
 
Angular presentation
Angular presentationAngular presentation
Angular presentationMatus Szabo
 
Synapse india reviews on i phone and android os
Synapse india reviews on i phone and android osSynapse india reviews on i phone and android os
Synapse india reviews on i phone and android ossaritasingh19866
 
Android | Busy Java Developers Guide to Android: UI | Ted Neward
Android | Busy Java Developers Guide to Android: UI | Ted NewardAndroid | Busy Java Developers Guide to Android: UI | Ted Neward
Android | Busy Java Developers Guide to Android: UI | Ted NewardJAX London
 

Similar to 01 06 - android programming basics (20)

Android layouts
Android layoutsAndroid layouts
Android layouts
 
Lec005 android start_program
Lec005 android start_programLec005 android start_program
Lec005 android start_program
 
Designing and implementing_android_uis_for_phones_and_tablets
Designing and implementing_android_uis_for_phones_and_tabletsDesigning and implementing_android_uis_for_phones_and_tablets
Designing and implementing_android_uis_for_phones_and_tablets
 
Android UI Development
Android UI DevelopmentAndroid UI Development
Android UI Development
 
Lecture 02: Android Layouts.pptx
Lecture 02: Android Layouts.pptxLecture 02: Android Layouts.pptx
Lecture 02: Android Layouts.pptx
 
Ad103 - Have it Your Way: Extending IBM Lotus Domino Designer
Ad103 - Have it Your Way: Extending IBM Lotus Domino DesignerAd103 - Have it Your Way: Extending IBM Lotus Domino Designer
Ad103 - Have it Your Way: Extending IBM Lotus Domino Designer
 
Implementing a Symfony Based CMS in a Publishing Company
Implementing a Symfony Based CMS in a Publishing CompanyImplementing a Symfony Based CMS in a Publishing Company
Implementing a Symfony Based CMS in a Publishing Company
 
mobile application development -unit-3-
mobile application development  -unit-3-mobile application development  -unit-3-
mobile application development -unit-3-
 
Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart Jfokus
 
RomaFramework Tutorial Basics
RomaFramework Tutorial BasicsRomaFramework Tutorial Basics
RomaFramework Tutorial Basics
 
Android development orientation for starters v2
Android development orientation for starters v2Android development orientation for starters v2
Android development orientation for starters v2
 
Lavacon 2014 responsive design in your hat
Lavacon 2014   responsive design in your hatLavacon 2014   responsive design in your hat
Lavacon 2014 responsive design in your hat
 
Android training day 2
Android training day 2Android training day 2
Android training day 2
 
Angular presentation
Angular presentationAngular presentation
Angular presentation
 
L05 Design Patterns
L05 Design PatternsL05 Design Patterns
L05 Design Patterns
 
Synapse india mobile apps update
Synapse india mobile apps updateSynapse india mobile apps update
Synapse india mobile apps update
 
Synapse india reviews on i phone and android os
Synapse india reviews on i phone and android osSynapse india reviews on i phone and android os
Synapse india reviews on i phone and android os
 
Android bootcamp-day1
Android bootcamp-day1Android bootcamp-day1
Android bootcamp-day1
 
Android | Busy Java Developers Guide to Android: UI | Ted Neward
Android | Busy Java Developers Guide to Android: UI | Ted NewardAndroid | Busy Java Developers Guide to Android: UI | Ted Neward
Android | Busy Java Developers Guide to Android: UI | Ted Neward
 
MSR Asia Summit
MSR Asia SummitMSR Asia Summit
MSR Asia Summit
 

More from Siva Kumar reddy Vasipally

More from Siva Kumar reddy Vasipally (10)

01 11 - graphical user interface - fonts-web-tab
01  11 - graphical user interface - fonts-web-tab01  11 - graphical user interface - fonts-web-tab
01 11 - graphical user interface - fonts-web-tab
 
01 10 - graphical user interface - others
01  10 - graphical user interface - others01  10 - graphical user interface - others
01 10 - graphical user interface - others
 
01 09 - graphical user interface - basic widgets
01  09 - graphical user interface - basic widgets01  09 - graphical user interface - basic widgets
01 09 - graphical user interface - basic widgets
 
01 08 - graphical user interface - layouts
01  08 - graphical user interface - layouts01  08 - graphical user interface - layouts
01 08 - graphical user interface - layouts
 
01 07 -android programming basics (cont)
01  07 -android programming basics (cont)01  07 -android programming basics (cont)
01 07 -android programming basics (cont)
 
01 05 - introduction xml
01  05 - introduction xml01  05 - introduction xml
01 05 - introduction xml
 
01 04 - android set up and creating an android project
01  04 - android set up and creating an android project01  04 - android set up and creating an android project
01 04 - android set up and creating an android project
 
01 03 - introduction to android
01  03 - introduction to android01  03 - introduction to android
01 03 - introduction to android
 
01 02 - introduction - adroid stack
01  02 - introduction - adroid stack01  02 - introduction - adroid stack
01 02 - introduction - adroid stack
 
01 01 - introduction to mobile application development
01  01 - introduction to mobile application development01  01 - introduction to mobile application development
01 01 - introduction to mobile application development
 

Recently uploaded

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 

01 06 - android programming basics

  • 2. Agenda Basic program structure Java-based layout XML-based layout Eclipse ADT visual layout editor Hybrid layout Project structure summary
  • 3. General Structure (Common to All Approaches)
  • 4. Three Main Approaches  • Java-based  – Use Java to define Strings, lay out window, create GUI controls, and assign event handlers. Like Swing programming.  • XML-based  – Use XML files to define Strings, lay out window, create GUI controls, and assign event handlers. The Java method will read the layout from XML file and pass it to setContentView.  • Hybrid  – Use an XML file to define Strings, lay out window and create GUI controls. Use Java to assign event handlers.  • Examples in this tutorial section  – Button that says “Show Greeting”. Small popup message appears when button is pressed.  – Implemented each of the three ways.
  • 9. Big Idea  • Approach  – Use Java to define Strings, lay out window, create GUI controls, and assign event handlers.  • Advantages  – Familiar to Java desktop developers. Like approach used for Swing, SWT, and AWT.  – Good for layouts that are dynamic (i.e., that change based on program logic).  • Disadvantages  – Harder to maintain (arguable, but general consensus)  – Works poorly with I18N  – Not generally recommended except for dynamic layouts  • But still acceptable for App Store. Whatever works best for your programmers and your app. No code police.
  • 13. Results on Physical Phone • Reminder – Configured phone (once only) – Shut down emulator, plugged in phone – R-clicked project, Run As->Android Application
  • 15. Big Idea  • Approach  – Use XML files to define Strings, lay out window, create GUI controls, and assign event handlers.  • Define layout and controls in res/layout/main.xml  • Define Strings in res/values/strings.xml  • Advantages  – Easier to maintain  – Works well with I18N  – Can use visual layout editor in Eclipse  – Standard/recommended approach (along with hybrid)  • Disadvantages  – Works poorly for dynamic layouts
  • 16. More Details  • res/layout/main.xml  – Define layout and controls with XML description  • <LinearLayout …>Define controls</LinearLayout>  – Refer to strings (from strings.xml) with @string/string_name  – Assign event handler with android:onClick  • res/values/strings.xml  – Define strings used in GUI or that might change with I18N  • Java code  – Refer to layout with R.layout.main (res/layout/main.xml)  – Refer to strings with getString(R.string.string_name)  – Refer to controls with findViewById(R.id.some_id)  • More info  – http://developer.android.com/guide/topics/ui/declaring-layout.html
  • 22. Eclipse ADT Visual Layout Editor  • Invoking  – When editing main.xml, click Graphical Layout  • Features  – Can interactively change layout attributes (vertical/horizontal, fill  characteristics, etc.)  – Can drag from palette of available GUI controls  – Can interactively set control characteristics (colors, fill, event handler, etc.)  – Shows visual preview  • Warning  – Although visual editor is very useful, you should still manually edit XML to fix indentation, order of attributes, use of obsolete attribute names (fill_parent instead of match_parent), and other stylistic things.
  • 25. Big Idea  • Approach  – Use XML files to define Strings, lay out window, and create GUI controls.  – Use Java to assign event handlers.  • Advantages  – Mostly same as XML-based approach  – But, since event handler needs to be edited by Java programmer anyhow, often makes more sense to assign it programmatically as well.  • Disadvantages  – Works poorly for dynamic layouts