Lesson Plan: Unit - 03
Subject: P15A2AAD - Android Application Development
Topic of Study: Displaying Text with TextView
Grade/Level: Master of Computer Applications
Objective: To understand the TextView and its properties
Time Allotment: 55 Minutes
- Displaying Text to Users with TextView
- One of the most basic user interface elements, or controls, in the Android SDK is the TextView control.
- You use it, quite simply, to draw text on the screen.
- You primarily use it to display fixed text strings or labels.
- Exa.
- Frequently, the TextView control is a child control within other screen elements and controls.
- As with most of the user interface elements, it is derived from View and is within the android.widget package.
- Because it is a View, all the standard attributes such as width, height, padding, and visibility can be applied to the object.
- First, though, let’s see how to put some quick text up on the screen.
- TextView tag is the XML layout file tag used to display text on the screen.
- You can set the android:text property of the TextView to be either a raw text string in the layout file or a reference to a string resource.
- Here, Both methods you can use to set the android:text attribute of a TextView.
- The first method sets the text attribute to a raw string;
- Exa.
- The second method uses a string resource called sample_text, which must be defined in the strings.xml resource file.
- Exa.
- To display this TextView on the screen, all your Activity needs to do is call the setContentView() method with the layout resource identifier in which you defined the preceding XML shown.
- Exa.
- You can change the text displayed programmatically by calling the setText() method on the TextView object.
- Retrieving the text is done with the getText() method.
- Exa.
- You can also use maxLines and minLines to control the maximum height and minimum height, respectively, that the Textview displays.
- Exa.
- Creating Contextual Links in Text
- The autoLink attribute has four values that you can use in combination with each other.
- When enabled, these autoLink attribute values create standard web-style links to the application that can act on that data type.
- Exa.
- Your text can contain the following values for the autoLink attribute:
- none: Disables all linking.
- web: Enables linking of URLs to web pages.
- email: Enables linking of email addresses to the mail client with the recipient filled.
- phone: Enables linking of phone numbers to the dialed application with the phone number filled out, ready to be dialed.
- map: Enables linking of street addresses to the map application to show the location.
- all: Enables all types of linking.
- Exa.