SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Downloaden Sie, um offline zu lesen
Developing Applications
   for Android

    Muhammad Usman Chaudhry
         SZABIST CS4615




                              Lecture # 4
Today - Detail in Design
    ● Android Layouts Basics
    ● Introduction to Layout Managers & their LayoutParams
       ○ Linear Layout
       ○ Relative Layout
       ○ Table Layout
       ○ Grid Layout
    ● Basic Controls (Most commonly used)
       ○ Text Fields
       ○ TextView
       ○ Buttons (Button, ImageButton, RadioButton, ToggleButton)
       ○ Checkboxes
       ○ Spinners
       ○ ImageView


Muhammad Usman Chaudhry        CS4615                         SZABIST
Today - Detail in Design
    ● Accessing Resources
      ○ via Java Code
      ○ from within XML




Muhammad Usman Chaudhry     CS4615   SZABIST
Android Layouts
    ● Can be defined completely in,
      ○ Java Files
      ○ XML Files
      ○ Both Java & XML files
    ● We mostly define layouts in XML files
    ● Flow structure for standard XML Layout is,
      ○ Declare UI elements in XML file
      ○ Instantiate & access elements at runtime using R.




Muhammad Usman Chaudhry       CS4615                        SZABIST
Layout Managers
    ● Behave like containers for other views.
    ● Implements strategies to manage size, position of its
      children.
    ● Layout managers used in android:
       ○ Linear Layout
       ○ Relative Layout
       ○ Table Layout
       ○ Grid Layout
    ● Another layout manager known as Absolute Layout is no
      more available and deprecated.




Muhammad Usman Chaudhry       CS4615                          SZABIST
Layout Params
    ● Define attributes available to all the child controls within
      Layout Manager.
    ● All type of layout managers have various layout params that
      define position, weight, gravity, etc. for a child within that
      certain layout manager, for instance:
      ○ In LinearLayout.LayoutParams we have:
           ■ Gravity (android:layout_gravity)
           ■ Weight (android:layout_weight)
      ○ In RelativeLayout.LayoutParams we have:
           ■ Layout Above (android:layout_above)
           ■ Layout Top (android:layout_alignTop)
           ■ and many more...


Muhammad Usman Chaudhry          CS4615                          SZABIST
Linear Layout
    ● Aligns all the children in one direction
      ○ Either Horizontally
      ○ Or Vertically
    ● Children are stacked one after another
    ● We may nest multiple linear layouts or
      linear layout within some other layout
    ● Let's have a look at example code for Linear
      Layout, understand it, and then run it on
      Eclipse and make few changes to cater
      nested linear layouts.
Muhammad Usman Chaudhry   CS4615                SZABIST
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"


   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:paddingLeft="16dp"
   android:paddingRight="16dp"
   android:orientation="vertical" >
   <EditText
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:hint="@string/username" />
   <EditText
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:inputType="textPassword"
     android:hint="@string/password" />
   <Button
     android:layout_width="100dp"
     android:layout_height="wrap_content"
     android:layout_gravity="right"
     android:text="@string/login" />
</LinearLayout>




Muhammad Usman Chaudhry                                                    CS4615   SZABIST
Relative Layout
    ● Display child views in relative positions
    ● We may specify position in relation with
      parent or siblings of a view
    ● Eliminates the need of nested views
    ● Many nested linear layouts can be
      converted into one Relative Layout
    ● Let's have a look at example code for Linear
      Layout, understand it, then run it on Eclipse
      and play with it to understand few more
      things.
Muhammad Usman Chaudhry   CS4615                SZABIST
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.
com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:paddingLeft="16dp"
  android:paddingRight="16dp"
  android:orientation="vertical" >
  <EditText
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:id="@+id/username"
     android:hint="@string/username" />
  <EditText
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:id="@+id/password"
     android:layout_below="@+id/username"
     android:inputType="textPassword"
     android:hint="@string/password" />
  <Button
     android:id="@+id/register"
     android:layout_width="100dp"
     android:layout_height="wrap_content"
      android:layout_alignRight="@+id/password"
     android:layout_below="@+id/password"
     android:text="@string/loginr" />
</RelativeLayout>




Muhammad Usman Chaudhry                                  CS4615   SZABIST
Table Layout
    ● Keep all the child views in a table.
    ● In Table Layout, TableRow represent one
      row.
    ● All children in a TableRow are columns.
    ● Useful to display data in rows and columns.
    ● Not useful for designing complete user
      interfaces.
    ● Let's have a look at basic example and then
      try-it-out on Eclipse.

Muhammad Usman Chaudhry   CS4615               SZABIST
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"

   android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TableRow android:layout_width="fill_parent" >
     <EditText
       android:id="@+id/username"
       android:layout_width="140dp"
       android:layout_height="match_parent"
       android:hint="@string/username" />
     <EditText
       android:id="@+id/password"
       android:layout_width="140dp"
       android:layout_height="match_parent"
       android:hint="@string/password" />
       android:inputType="textPassword"
  </TableRow>
  <Button
     android:id="@+id/login"
     android:layout_width="100dp"
     android:layout_height="wrap_content"
     android:text="@string/login" />
</TableLayout>




Muhammad Usman Chaudhry                                                   CS4615   SZABIST
Grid Layout
    ● Places all of its child views in a rectangular
      grid.
    ● By default you we may define rowCount &
      colCount and all child views in a grid layout
      behaves like a matrix.
    ● We can manually define which row/col a
      certain object belongs to using layout_row
      & layout_column property.
    ● Useful for displaying image galleries, grid
      data and similar things.
Muhammad Usman Chaudhry   CS4615                  SZABIST
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"

  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:columnCount="2"
  android:rowCount="2">
  <EditText
     android:id="@+id/username"
     android:layout_width="140dp"
     android:layout_height="match_parent"
     android:hint="@string/username" />
  <EditText
     android:id="@+id/password"
     android:layout_width="140dp"
     android:layout_height="match_parent"
     android:inputType="textPassword"
     android:hint="@string/password" />
  <Button android:id="@+id/login"
     android:layout_width="100dp"
     android:layout_height="wrap_content"
     android:text="@string/login" />
</GridLayout>




Muhammad Usman Chaudhry                                                  CS4615   SZABIST
Basic Input Controls
    ● Input controls are used to take data from
      user.
    ● Most commonly used controls in Android
      Ecosystem are:
         ○   Text Fields
         ○   TextView
         ○   Buttons (Button, ImageButton, RadioButton, ToggleButton)
         ○   Checkboxes
         ○   Spinners
         ○   ImageView
    ●   Let's study them one by one

Muhammad Usman Chaudhry           CS4615                          SZABIST
Text Fields
     ● Text Fields allow users to type text in your application.
     ● Text fields have different types like:
        ○ Plain Text
        ○ Person Name
        ○ Password
        ○ Email
        ○ Phone
        ○ Postal Address
        ○ Multiline Text
        ○ Time
        ○ Date
        ○ Number (Signed/Unsigned)
     ● All of the Text Fields mentioned above are merely attributes of
       EditText.
     ● Let's try them all on Eclipse.


Muhammad Usman Chaudhry              CS4615                              SZABIST
Text View
    ● TextView is used to display text on screen.
    ● EditText, Button are direct subclasses of TextView.
    ● TextView doesn't allow editing in itself.
    ● It works more like a label.
    ● Some interesting attributes of textview are:
       ○ shadowColor
       ○ shadowRadius
       ○ shadowDy, shadowDx
    ● Let's try this on Eclipse.




Muhammad Usman Chaudhry      CS4615                         SZABIST
Buttons
    ● Buttons allows user to perform some action.
    ● Android have following button types available,
      sequence is Control Name (Class Name):
      ○ Button (Button)
      ○ Image Button (ImageButton)
      ○ Toggle Buttons (ToggleButton)
      ○ Radio Buttons (RadioButton)
    ● All buttons have different classes and XML tags to
      represent them unlike the Text Fields (That had only
      one tag i.e. EditText)
    ● Let's try them all on Eclipse.


Muhammad Usman Chaudhry      CS4615                      SZABIST
Checkboxes
    ● Allows users to select one or more options from the
      set.
    ● Let's try on Eclipse.




Muhammad Usman Chaudhry      CS4615                         SZABIST
Spinners
    ●   Spinners are used to select one value from a set.
    ●   Unlike it's name don't confuse it with loading spinner.
    ●   They're combo boxes of android.
    ●   Let's try on Eclipse.




Muhammad Usman Chaudhry         CS4615                        SZABIST
ImageView
    ● ImageView is used to display an image.
    ● Can load images from various sources, eg.
      drawables/content providers.
    ● Take care of measurements & scaling.
    ● Various other display options available like scaling &
      tinting.
    ● Let's Try-It-On-Eclipse.




Muhammad Usman Chaudhry       CS4615                           SZABIST
Accessing Resources
    ● Though we have already done some examples
      but it's time to know what is happening.
    ● All resources in XML can be accessed via
      findViewById method in Java Code.
      ○ <ResourceType> objectName =
         (<ResourceType>) findViewById(R.id.
         viewId);
      ○ <ResourceType> can be Spinner, TextView,
         EditText or any other field.


Muhammad Usman Chaudhry   CS4615               SZABIST
Accessing Resources
    ● Similarly we can access other resources like
      value strings, images from within the XML file
      as:
      ○ @string/string_label
      ○ @drawable/image_name




Muhammad Usman Chaudhry   CS4615                   SZABIST
Lab Session
    ● Create multiple layout files
      ○ Every file will contain different LayoutManager
         but same controls.
      ○ Use all the LayoutManagers and Controls
         explained in the class.
      ○ So it'll be like:
         ■ LinearLayout - All controls (ll.xml)
         ■ RelativeLayout - All controls (rl.xml)
         ■ TableLayout - All controls (tl.xml)
         ■ GridLayout - All controls (gl.xml)
      ○ change setContentView() to display relevant
         LayoutManager.
Muhammad Usman Chaudhry     CS4615                        SZABIST
Next Week Due
    ● Quiz
    ● Assignment




Muhammad Usman Chaudhry   CS4615   SZABIST
Quiz
    ● Everything from Lecture#2 & Lecture#4
    ● All topics from Lecture#3 except DVCS
    ● You may obtain lectures from Group, studnets who
      haven't joined yet, may join:
      ○ SZABIST-FALL2012-ANDROID
      ○ on groups.google.com




Muhammad Usman Chaudhry    CS4615                    SZABIST
Assignment
     ●   Create a registration form with following fields:
          ○ First Name
          ○ Last Name
          ○ Date of Birth
          ○ Gender
          ○ Username
          ○ Password
          ○ Verify Password
          ○ Email Address
          ○ Phone Number
          ○ Address
          ○ Country
          ○ Register Button
     ●   Create the same form in, LinearLayout, RelativeLayout, TableLayout &
         GridLayout.
     ●   Selection of right control for the right field is important.

Muhammad Usman Chaudhry               CS4615                                SZABIST
Assignment
     ●   Email your assignment with complete source files to:
          ○ muhammad.usman.chaudhry@gmail.com
          ○ Subject: SZABIST ANDROID FALL2012 ASSIGNMENT#1- STDID - NAME
          ○ I'll automatically award 40% marks upon submission, rest will be
            graded upon quality of code, but in case of copy/paste, 0 will be
            given.




Muhammad Usman Chaudhry               CS4615                                SZABIST
Coming up next
    ●   Event Listeners, Handlers, etc.
    ●   Multiple Activities (Switching, Data Passing, Stack
        Management)
    ●   Intents
    ●   And much more...




Muhammad Usman Chaudhry          CS4615                       SZABIST

Weitere ähnliche Inhalte

Ähnlich wie Developing Applications for Android - Lecture#4

Android training day 2
Android training day 2Android training day 2
Android training day 2Vivek Bhusal
 
Developing Applications for Android - Lecture#1
Developing Applications for Android - Lecture#1Developing Applications for Android - Lecture#1
Developing Applications for Android - Lecture#1Usman Chaudhry
 
W1_Lec01_Lec02_Layouts.pptx
W1_Lec01_Lec02_Layouts.pptxW1_Lec01_Lec02_Layouts.pptx
W1_Lec01_Lec02_Layouts.pptxssuserc1e786
 
Most Essential AutoCAD Commands
Most Essential AutoCAD CommandsMost Essential AutoCAD Commands
Most Essential AutoCAD CommandsRavi Bhadauria
 
Build tons of multi-device JavaScript applications - Part 2 : (black) Magic S...
Build tons of multi-device JavaScript applications - Part 2 : (black) Magic S...Build tons of multi-device JavaScript applications - Part 2 : (black) Magic S...
Build tons of multi-device JavaScript applications - Part 2 : (black) Magic S...Skilld
 
WMP_MP02_revd(10092023).pptx
WMP_MP02_revd(10092023).pptxWMP_MP02_revd(10092023).pptx
WMP_MP02_revd(10092023).pptxfahmi324663
 
Printing photos-html-using-android
Printing photos-html-using-androidPrinting photos-html-using-android
Printing photos-html-using-androidKetan Raval
 
Accessibilita con stile - CSS per il web moderno e accessibile
Accessibilita con stile - CSS per il web moderno e accessibileAccessibilita con stile - CSS per il web moderno e accessibile
Accessibilita con stile - CSS per il web moderno e accessibileMassimo Artizzu
 
Android Erası 2 - UI və layoutlar
Android Erası 2 - UI və layoutlarAndroid Erası 2 - UI və layoutlar
Android Erası 2 - UI və layoutlarOrkhan Ahmadov
 
Javascript Programming according to Industry Standards.pptx
Javascript Programming according to Industry Standards.pptxJavascript Programming according to Industry Standards.pptx
Javascript Programming according to Industry Standards.pptxMukundSonaiya1
 
Rajab Davudov - Android UI Design: Layouts
Rajab Davudov - Android UI Design: LayoutsRajab Davudov - Android UI Design: Layouts
Rajab Davudov - Android UI Design: LayoutsRashad Aliyev
 
Civil project .ppt
Civil project .pptCivil project .ppt
Civil project .pptPremArumalla
 
Google I/O 2019 - what's new in Android Q and Jetpack
Google I/O 2019 - what's new in Android Q and JetpackGoogle I/O 2019 - what's new in Android Q and Jetpack
Google I/O 2019 - what's new in Android Q and JetpackSunita Singh
 
Front-End Developer's Career Roadmap
Front-End Developer's Career RoadmapFront-End Developer's Career Roadmap
Front-End Developer's Career RoadmapWebStackAcademy
 
From Back to Front: Rails To React Family
From Back to Front: Rails To React FamilyFrom Back to Front: Rails To React Family
From Back to Front: Rails To React FamilyKhor SoonHin
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Manoj Ellappan
 

Ähnlich wie Developing Applications for Android - Lecture#4 (20)

Android training day 2
Android training day 2Android training day 2
Android training day 2
 
Developing Applications for Android - Lecture#1
Developing Applications for Android - Lecture#1Developing Applications for Android - Lecture#1
Developing Applications for Android - Lecture#1
 
W1_Lec01_Lec02_Layouts.pptx
W1_Lec01_Lec02_Layouts.pptxW1_Lec01_Lec02_Layouts.pptx
W1_Lec01_Lec02_Layouts.pptx
 
AutoCAD Architecture
AutoCAD ArchitectureAutoCAD Architecture
AutoCAD Architecture
 
Most Essential AutoCAD Commands
Most Essential AutoCAD CommandsMost Essential AutoCAD Commands
Most Essential AutoCAD Commands
 
Build tons of multi-device JavaScript applications - Part 2 : (black) Magic S...
Build tons of multi-device JavaScript applications - Part 2 : (black) Magic S...Build tons of multi-device JavaScript applications - Part 2 : (black) Magic S...
Build tons of multi-device JavaScript applications - Part 2 : (black) Magic S...
 
WMP_MP02_revd(10092023).pptx
WMP_MP02_revd(10092023).pptxWMP_MP02_revd(10092023).pptx
WMP_MP02_revd(10092023).pptx
 
Constraint layout - New Hope
Constraint layout - New HopeConstraint layout - New Hope
Constraint layout - New Hope
 
Printing photos-html-using-android
Printing photos-html-using-androidPrinting photos-html-using-android
Printing photos-html-using-android
 
Accessibilita con stile - CSS per il web moderno e accessibile
Accessibilita con stile - CSS per il web moderno e accessibileAccessibilita con stile - CSS per il web moderno e accessibile
Accessibilita con stile - CSS per il web moderno e accessibile
 
Chapter 5 - Layouts
Chapter 5 - LayoutsChapter 5 - Layouts
Chapter 5 - Layouts
 
Android Erası 2 - UI və layoutlar
Android Erası 2 - UI və layoutlarAndroid Erası 2 - UI və layoutlar
Android Erası 2 - UI və layoutlar
 
Javascript Programming according to Industry Standards.pptx
Javascript Programming according to Industry Standards.pptxJavascript Programming according to Industry Standards.pptx
Javascript Programming according to Industry Standards.pptx
 
Rajab Davudov - Android UI Design: Layouts
Rajab Davudov - Android UI Design: LayoutsRajab Davudov - Android UI Design: Layouts
Rajab Davudov - Android UI Design: Layouts
 
Civil project .ppt
Civil project .pptCivil project .ppt
Civil project .ppt
 
Google I/O 2019 - what's new in Android Q and Jetpack
Google I/O 2019 - what's new in Android Q and JetpackGoogle I/O 2019 - what's new in Android Q and Jetpack
Google I/O 2019 - what's new in Android Q and Jetpack
 
Front-End Developer's Career Roadmap
Front-End Developer's Career RoadmapFront-End Developer's Career Roadmap
Front-End Developer's Career Roadmap
 
From Back to Front: Rails To React Family
From Back to Front: Rails To React FamilyFrom Back to Front: Rails To React Family
From Back to Front: Rails To React Family
 
Better java with design
Better java with designBetter java with design
Better java with design
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1
 

Kürzlich hochgeladen

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Developing Applications for Android - Lecture#4

  • 1. Developing Applications for Android Muhammad Usman Chaudhry SZABIST CS4615 Lecture # 4
  • 2. Today - Detail in Design ● Android Layouts Basics ● Introduction to Layout Managers & their LayoutParams ○ Linear Layout ○ Relative Layout ○ Table Layout ○ Grid Layout ● Basic Controls (Most commonly used) ○ Text Fields ○ TextView ○ Buttons (Button, ImageButton, RadioButton, ToggleButton) ○ Checkboxes ○ Spinners ○ ImageView Muhammad Usman Chaudhry CS4615 SZABIST
  • 3. Today - Detail in Design ● Accessing Resources ○ via Java Code ○ from within XML Muhammad Usman Chaudhry CS4615 SZABIST
  • 4. Android Layouts ● Can be defined completely in, ○ Java Files ○ XML Files ○ Both Java & XML files ● We mostly define layouts in XML files ● Flow structure for standard XML Layout is, ○ Declare UI elements in XML file ○ Instantiate & access elements at runtime using R. Muhammad Usman Chaudhry CS4615 SZABIST
  • 5. Layout Managers ● Behave like containers for other views. ● Implements strategies to manage size, position of its children. ● Layout managers used in android: ○ Linear Layout ○ Relative Layout ○ Table Layout ○ Grid Layout ● Another layout manager known as Absolute Layout is no more available and deprecated. Muhammad Usman Chaudhry CS4615 SZABIST
  • 6. Layout Params ● Define attributes available to all the child controls within Layout Manager. ● All type of layout managers have various layout params that define position, weight, gravity, etc. for a child within that certain layout manager, for instance: ○ In LinearLayout.LayoutParams we have: ■ Gravity (android:layout_gravity) ■ Weight (android:layout_weight) ○ In RelativeLayout.LayoutParams we have: ■ Layout Above (android:layout_above) ■ Layout Top (android:layout_alignTop) ■ and many more... Muhammad Usman Chaudhry CS4615 SZABIST
  • 7. Linear Layout ● Aligns all the children in one direction ○ Either Horizontally ○ Or Vertically ● Children are stacked one after another ● We may nest multiple linear layouts or linear layout within some other layout ● Let's have a look at example code for Linear Layout, understand it, and then run it on Eclipse and make few changes to cater nested linear layouts. Muhammad Usman Chaudhry CS4615 SZABIST
  • 8. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingLeft="16dp" android:paddingRight="16dp" android:orientation="vertical" > <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/username" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="textPassword" android:hint="@string/password" /> <Button android:layout_width="100dp" android:layout_height="wrap_content" android:layout_gravity="right" android:text="@string/login" /> </LinearLayout> Muhammad Usman Chaudhry CS4615 SZABIST
  • 9. Relative Layout ● Display child views in relative positions ● We may specify position in relation with parent or siblings of a view ● Eliminates the need of nested views ● Many nested linear layouts can be converted into one Relative Layout ● Let's have a look at example code for Linear Layout, understand it, then run it on Eclipse and play with it to understand few more things. Muhammad Usman Chaudhry CS4615 SZABIST
  • 10. <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android. com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingLeft="16dp" android:paddingRight="16dp" android:orientation="vertical" > <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/username" android:hint="@string/username" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/password" android:layout_below="@+id/username" android:inputType="textPassword" android:hint="@string/password" /> <Button android:id="@+id/register" android:layout_width="100dp" android:layout_height="wrap_content" android:layout_alignRight="@+id/password" android:layout_below="@+id/password" android:text="@string/loginr" /> </RelativeLayout> Muhammad Usman Chaudhry CS4615 SZABIST
  • 11. Table Layout ● Keep all the child views in a table. ● In Table Layout, TableRow represent one row. ● All children in a TableRow are columns. ● Useful to display data in rows and columns. ● Not useful for designing complete user interfaces. ● Let's have a look at basic example and then try-it-out on Eclipse. Muhammad Usman Chaudhry CS4615 SZABIST
  • 12. <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TableRow android:layout_width="fill_parent" > <EditText android:id="@+id/username" android:layout_width="140dp" android:layout_height="match_parent" android:hint="@string/username" /> <EditText android:id="@+id/password" android:layout_width="140dp" android:layout_height="match_parent" android:hint="@string/password" /> android:inputType="textPassword" </TableRow> <Button android:id="@+id/login" android:layout_width="100dp" android:layout_height="wrap_content" android:text="@string/login" /> </TableLayout> Muhammad Usman Chaudhry CS4615 SZABIST
  • 13. Grid Layout ● Places all of its child views in a rectangular grid. ● By default you we may define rowCount & colCount and all child views in a grid layout behaves like a matrix. ● We can manually define which row/col a certain object belongs to using layout_row & layout_column property. ● Useful for displaying image galleries, grid data and similar things. Muhammad Usman Chaudhry CS4615 SZABIST
  • 14. <?xml version="1.0" encoding="utf-8"?> <GridLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="wrap_content" android:columnCount="2" android:rowCount="2"> <EditText android:id="@+id/username" android:layout_width="140dp" android:layout_height="match_parent" android:hint="@string/username" /> <EditText android:id="@+id/password" android:layout_width="140dp" android:layout_height="match_parent" android:inputType="textPassword" android:hint="@string/password" /> <Button android:id="@+id/login" android:layout_width="100dp" android:layout_height="wrap_content" android:text="@string/login" /> </GridLayout> Muhammad Usman Chaudhry CS4615 SZABIST
  • 15. Basic Input Controls ● Input controls are used to take data from user. ● Most commonly used controls in Android Ecosystem are: ○ Text Fields ○ TextView ○ Buttons (Button, ImageButton, RadioButton, ToggleButton) ○ Checkboxes ○ Spinners ○ ImageView ● Let's study them one by one Muhammad Usman Chaudhry CS4615 SZABIST
  • 16. Text Fields ● Text Fields allow users to type text in your application. ● Text fields have different types like: ○ Plain Text ○ Person Name ○ Password ○ Email ○ Phone ○ Postal Address ○ Multiline Text ○ Time ○ Date ○ Number (Signed/Unsigned) ● All of the Text Fields mentioned above are merely attributes of EditText. ● Let's try them all on Eclipse. Muhammad Usman Chaudhry CS4615 SZABIST
  • 17. Text View ● TextView is used to display text on screen. ● EditText, Button are direct subclasses of TextView. ● TextView doesn't allow editing in itself. ● It works more like a label. ● Some interesting attributes of textview are: ○ shadowColor ○ shadowRadius ○ shadowDy, shadowDx ● Let's try this on Eclipse. Muhammad Usman Chaudhry CS4615 SZABIST
  • 18. Buttons ● Buttons allows user to perform some action. ● Android have following button types available, sequence is Control Name (Class Name): ○ Button (Button) ○ Image Button (ImageButton) ○ Toggle Buttons (ToggleButton) ○ Radio Buttons (RadioButton) ● All buttons have different classes and XML tags to represent them unlike the Text Fields (That had only one tag i.e. EditText) ● Let's try them all on Eclipse. Muhammad Usman Chaudhry CS4615 SZABIST
  • 19. Checkboxes ● Allows users to select one or more options from the set. ● Let's try on Eclipse. Muhammad Usman Chaudhry CS4615 SZABIST
  • 20. Spinners ● Spinners are used to select one value from a set. ● Unlike it's name don't confuse it with loading spinner. ● They're combo boxes of android. ● Let's try on Eclipse. Muhammad Usman Chaudhry CS4615 SZABIST
  • 21. ImageView ● ImageView is used to display an image. ● Can load images from various sources, eg. drawables/content providers. ● Take care of measurements & scaling. ● Various other display options available like scaling & tinting. ● Let's Try-It-On-Eclipse. Muhammad Usman Chaudhry CS4615 SZABIST
  • 22. Accessing Resources ● Though we have already done some examples but it's time to know what is happening. ● All resources in XML can be accessed via findViewById method in Java Code. ○ <ResourceType> objectName = (<ResourceType>) findViewById(R.id. viewId); ○ <ResourceType> can be Spinner, TextView, EditText or any other field. Muhammad Usman Chaudhry CS4615 SZABIST
  • 23. Accessing Resources ● Similarly we can access other resources like value strings, images from within the XML file as: ○ @string/string_label ○ @drawable/image_name Muhammad Usman Chaudhry CS4615 SZABIST
  • 24. Lab Session ● Create multiple layout files ○ Every file will contain different LayoutManager but same controls. ○ Use all the LayoutManagers and Controls explained in the class. ○ So it'll be like: ■ LinearLayout - All controls (ll.xml) ■ RelativeLayout - All controls (rl.xml) ■ TableLayout - All controls (tl.xml) ■ GridLayout - All controls (gl.xml) ○ change setContentView() to display relevant LayoutManager. Muhammad Usman Chaudhry CS4615 SZABIST
  • 25. Next Week Due ● Quiz ● Assignment Muhammad Usman Chaudhry CS4615 SZABIST
  • 26. Quiz ● Everything from Lecture#2 & Lecture#4 ● All topics from Lecture#3 except DVCS ● You may obtain lectures from Group, studnets who haven't joined yet, may join: ○ SZABIST-FALL2012-ANDROID ○ on groups.google.com Muhammad Usman Chaudhry CS4615 SZABIST
  • 27. Assignment ● Create a registration form with following fields: ○ First Name ○ Last Name ○ Date of Birth ○ Gender ○ Username ○ Password ○ Verify Password ○ Email Address ○ Phone Number ○ Address ○ Country ○ Register Button ● Create the same form in, LinearLayout, RelativeLayout, TableLayout & GridLayout. ● Selection of right control for the right field is important. Muhammad Usman Chaudhry CS4615 SZABIST
  • 28. Assignment ● Email your assignment with complete source files to: ○ muhammad.usman.chaudhry@gmail.com ○ Subject: SZABIST ANDROID FALL2012 ASSIGNMENT#1- STDID - NAME ○ I'll automatically award 40% marks upon submission, rest will be graded upon quality of code, but in case of copy/paste, 0 will be given. Muhammad Usman Chaudhry CS4615 SZABIST
  • 29. Coming up next ● Event Listeners, Handlers, etc. ● Multiple Activities (Switching, Data Passing, Stack Management) ● Intents ● And much more... Muhammad Usman Chaudhry CS4615 SZABIST