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

Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Nikki Chapple
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
WomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneWomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneUiPathCommunity
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
QMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdfQMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdfROWELL MARQUINA
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialJoão Esperancinha
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 

Recently uploaded (20)

Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
WomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneWomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyone
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
QMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdfQMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdf
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorial
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 

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