Chapter 3
Download
1 / 31

Chapter 3 - PowerPoint PPT Presentation


  • 131 Views
  • Uploaded on

Chapter 3. Android User Input, Variables, and Operations. Objectives & Goals. In this chapter, you learn to: Use an Android theme Add a theme to the Android Manifest file Develop the user interface using Text Fields State the role of different Text Fields

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Chapter 3' - hans


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Chapter 3

Chapter 3

Android User Input, Variables, and Operations


Objectives goals

Objectives & Goals

In this chapter, you learn to:

Use an Android theme

Add a theme to the Android Manifest file

Develop the user interface using Text Fields

State the role of different Text Fields

Display a hint using the Hint property

Develop the user interface using a Spinner control

Add text to the String table


Objectives goals continued

Objectives & Goals (continued)

Add a prompt to the Spinner control

Declare variables to hold data

Code the GetText() method

Understand arithmetic operations

Convert numeric data

Format numeric data

Code the SetText() method

Run the completed app in the emulator


Android themes

Android Themes

Engaging the user by requesting input customizes the user experience each time the application is executed

A theme is a style applied to an Activity or an entire application

The default theme is a title bar (often gray) with a black background


Android themes continued

AndroidThemes (continued)

  • Previewing a Theme

    • Check the main.xml file in the emulator to see what your screen looks like


Android themes continued1

AndroidThemes (continued)

Coding a Theme in the Android Manifest File

Insert this code into the AndroidManifest.xml fileandroid:theme="@android:style/Theme.Black.NoTitleBar“


Simplifying user input

Simplifying User Input

The onscreen keyboard is called a softkeyboard

Input can be in the form of tapping or gestures (using two fingers to pan, rotate, or zoom)

Primary design challenge is to simplify user experiences

Use legible fonts, simplify input, and optimize each device’s capabilities to maximize user experience


Simplifying user input continued

Simplifying User Input (continued)

Android Text Fields

Text Fields are the most common type of mobile input

Can be free-form plain text

Numbers

A person’s name, password, email, phone number

A date

Multiline text



Simplifying user input continued2
Simplifying User Input (continued)

  • Adding a Text Field

    • Use the Id property in the Properties pane to enter a name that begins with the prefix txt

    • Use descriptive names like txtTickets instead of txtText1


Simplifying user input continued3

Simplifying User Input (continued)

Setting the Hint Property for the Text Field

A hint is a short description of a field visible as light-colored text (called a watermark)


Simplifying user input continued4

Simplifying User Input (continued)

Coding the EditText Class for the Text Field

A variable is used in programming to contain data that changes during the execution of a program

Final variables can be initialized but cannot be changed

Insert this code to create a variable:

final EditText tickets=(EditText)findViewById(R.id.txtTickets);



Simplifying user input continued6

Simplifying User Input (continued)

Android Spinner Control

A Spinner control is similar to a drop-down list for selecting a single item from a fixed list

The spinner control displays a list of strings called items in a pop-up window

A string is a series of alphanumeric characters that can include spaces


Simplifying user input continued7

Simplifying User Input (continued)

Using the String Table

A file named strings.xml is part of all Android apps and contains a list of commonly used strings

Android loads the resources from the project’s String table

Android can select text using Localization which allows for changing text based on the user’s preferred language

A prompt is used to display instructions at the top of the spinner control


Simplifying user input continued8

Simplifying User Input (continued)

Adding a Spinner Control with String Array Entries

A Spinner property named Entries connects the String Array to the Spinner control

Coding the Spinner Control


Simplifying user input continued9

Simplifying User Input (continued)

Adding the Button, TextView, and ImageView Controls






Declaring variables

Declaring Variables

Primitive Data Types


Declaring variables1

Declaring Variables

String Data Type

A string can be a character, word, or phrase

Declaring the Variables

Typically declared at the beginning of an Activity

Variables must be declared before you can use them



Declaring variables3

Declaring Variables

GetText() Method

Read data stored in the EditText control with the GetText() method

Data is read in as a string, by default

A Parse class is used to convert strings into numbers



Working with mathematical operations1

Working with Mathematical Operations

Formatting Numbers

Currency format requires a dollar sign, a comma (if needed), a decimal point, and two decimal places

Java has a class called DecimalFormatthat provides patterns, such as $###,###.## for displaying on the Android screen


Displaying android output

Displaying Android Output

GetSelectedItem() Method

The GetSelectedItem() method returns the text label of the currently selected Spinner item

SetText () Method

The SetText() method displays text in a TextView control



Summary

Summary

Assign a theme to an Activity or an entire application to prevent apps from looking too similar

Define a theme in the Android Manifest file for each Activity

Use Text Fields to request input from users

Use a control’s Hint property to provide guidelines to users so they know what to enter

Use the EditText class to extract text users have entered and store that text in a variable

Use GetText() to get data and SetText() to display data


Summary continued

Summary (continued)

Strings.xml is part of every Android application

You can edit a string in the strings.xml file to update text anywhere in the application

Use GetSelectedItem() to return the text of the selected Spinner item

To use a variable, you must first declare it

Variables are declared at the beginning of an Activity

Convert variables to the correct data type using the Parse class


ad