chapter 1 - introduction to android.pdf
TRANSCRIPT
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
1/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 1
INTRODUCTION
A. Module Descriptions
This module explain about how to develop android application such as simple
calculator, ebook application and etc. In this module we will learn about basic for
android programming such as layout, image, text , dialog, widget, intent,
multimedia and database. Before learn this module , participants must have
knowledge about Java Programming, xml and android basic structure.
B. Module Manual
At the begining of lesson the participants learn about using ADT-Bundle Software
to develop Android Application. It will follow with creating mobile application
projects with Android programming.
C. Competence Standard
After learning this module the participants are able to develop mobile application
with Android programming.
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
2/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 2
LEARNING ACTIVITY I
INTRODUCTION TO ANDROID
A. Learning Objectives
In this section, we will be discussing the characteristics of mobile
devices and how it affects program development for these devices. We will be
introduced to the Android.
At the end of the lesson, the participants should be able to:
Creating a new blank project in Eclipse
Understanding errors Creating an emulator
Setting up and copying launch configurations
Running your first app
Studying the anatomy of a project
Creating Layout
Displaying Image
B. Description
1. Android Overview
Computing is more accessible than ever before. Handheld devices have
transformed into computing platforms.Be it a phone or a tablet, the mobile
device is now so capable of general-purpose computing that its becoming the
realpersonal computer (PC). Every traditional PC manufacturer isproducing
devices of variousform factors based on the Android OS. The battles between
operating systems, computing platforms, programming languages, and
development frameworks are being shifted and reapplied to mobile devices.
We are also seeing a surge in mobile programming as more and more IT
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
3/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 3
applications start to offer mobile counterparts. In this book, well show you
how to take advantage of your Java skills to write programs for devices that
run on Googles Android platform (http://developer.android.com/index.html),
an open source platform for mobile and tablet development.
Why Develop for Android?
Market share
As a developer, you have an opportunity to develop apps for a fairly new
market that is booming on a daily basis. Android is currently set to outpace
many other carriers in market share in the industry in coming months. With
so many users, its never been easier to write an application that can be
downloaded and used by real people! The Android Market puts your app
right into your users hands easily! Users dont have to go searching the
Internet to find an app to install. They just simply go to the Android Market
that is preinstalled on their device, and they have access to all your apps.
Because the Android Market comes preinstalled on most Android devices
(I discuss a few exceptions later), users typically search the Android
Market forall of their app needs. Its not hard to see an apps number of
downloads soar in just a few days. Time to market
With all the application programming interfaces (APIs) that Android comes
packed with, its easy to develop full-featured applications in a relatively
short time frame. After youve signed up with the Android Market, just
upload your apps and publish them. Wait, you may say, are you sure?
Why, yes, I am! Unlike other mobile marketplaces, the Android Market has
no app-approval process. All you have to do is write apps and publish
them.Technically, anyone can publish anything, but its good karma to
keep within Googles terms of service and keep your apps family-friendly.
Remember that Android users come from diverse areas of the world and
are in all age categories.
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
4/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 4
Open platform
The Android operating system is open platform,meaning that its not tied
toone hardware manufacturer and/or one provider. As you can imagine,
the openness of Android is allowing it to gain market share quickly. All
hardware manufacturers and providers can make and sell Android
devices. The Android source code is available at
http://source.android.comfor you to view and/or modify. Nothing is holding
you back from digging into the source code to see how a certain task is
handled. The open-source code allows phone manufacturers to create
custom user interfaces (UIs) and add built-in features to some devices.
This also puts all developers on an even playing field. Everyone can
access the raw Android source code.
Android Programming Basics
If youve never programmed before, this book may not be the best place to
start. I advise that you pick up a copy of Beginning Programming with Java
For Dummies,by Barry Burd (Wiley Publishing), to learn the ropes. After you
have a basic understanding of Java under your belt, you should be ready totackle this book.
Although the majority of Android is Java, small parts of the framework arent.
Android also encompasses the XML language as well as basic Apache Ant
scripting for build processes. I advise you to have a basic understanding of
XML before delving into this book.
If you need an introduction to XML, check out XML For Dummies,by Lucinda
Dykes and Ed Tittel (Wiley). If you already know Java and XML,
congratulations youre ahead of the curve!
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
5/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 5
Java: Your Android programming language
Android applications are written in Java not the full-blown Java that J2EE
developers are used to, but a subset of Java that is sometimes known as the
Dalvik virtual machine.This smaller subset of Java excludes classes that dont
make sense for mobile devices. If you have any experience in Java, you
should be right at home.
It may be a good idea to keep a Java reference book on hand, but in any ase,
you can always Google what you dont understand. Because Java is nothing
new, you can find plenty of examples on the Web that demonstrate how to do
just about anything.
In Java source code, not all libraries are included. Verify that the package is
available to you. If its not, an alternative is probably bundled with Android that
can work for your needs.
Activities
Android applications are made up of one or more activities. Your app must
contain at least one activity, but an Android application can contain several.Think of an activity as being a container for your UI, holding your UI as well as
the code that runs it. Its kind of like a form, for you Windows programmers out
there.
Intents
Intentsmake up the core message system that runs Android. An intent is
composed of an action that it needs to perform (View, Edit, Dial, and so on)
and data. The action is the general action to be performed when the intent is
received, and the data is the data to operate on. The data might be a contact
item, for example.
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
6/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 6
Intents are used to start activities and to communicate among various parts of
the Android system. Your application can either broadcast an intent or receive
an intent.
Cursorless controls
Unlike PCs, which let you use a mouse to move the cursor across the screen,
Android devices let you use your fingers to do just about anything a mouse
can do. But how do you right-click? Instead of supporting right-clicking,
Android has implemented the long press. Press and hold a button, icon, or
screen for an extended period of time, and a context menu appears. As a
developer, you can create and manipulate context menus. You can allow
users to use two fingers on an Android device instead of just one mouse
cursor, for example. Keep in mind that fingers come in all sizes, however, and
design your user interface accordingly. Make the buttons large enough, with
enough spacing, so that even users with large fingers can interact with your
apps easily.
Views and widgets
What the heck is a view? A viewis a basic UI element a rectangular areaon the screen that is responsible for drawing and event handling. I like to think
of views as being basic controls, such as a label control in HTML. Here are a
few examples of views:
ContextMenu
Menu
View
Surface view
Widgetsare more-advanced UI elements, such as check boxes. Think of them
as being the controls that your users interact with. Here are a few widgets:
Button
CheckBox
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
7/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 7
DatePicker
DigitalClock
Gallery
FrameLayout
ImageView
RelativeLayout
PopupWindow
Many more widgets are ready for you to use. Check out the android.
widgetpackage in the Android documentation at http://developer.
android.com/reference/android/widget/package-summary.html for complete
details.
Background services
If youre a Windows user, you may already know what a serviceis: an
application that runs in the background and doesnt necessarily have a UI. A
classic example is an antivirus application that usually runs in the background
as a service. Even though you dont see it, you know that its running.
2. Software for Development
Developer Tools
The Android Developer Tools (ADT) plugin for Eclipse provides a
professional-grade development environment for building Android apps. It's a
full Java IDE with advanced features to help you build, test, debug, and
package your Android apps.
Full Java IDE
Android-specific refactoring, quick fixes, integrated navigation between
Java and XML resources.
Enhanced XML editors for Android XML resources.
http://developer/http://developer/http://developer/ -
7/29/2019 Chapter 1 - Introduction to Android.pdf
8/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 8
Static analysis tools to catch performance, usability, and correctness
problems.
Build support for complex projects, command-line support for CI through
Ant. Includes ProGuard and app-signing.
Template-based wizard to create standard Android projects and
component
Graphical UI Builders
Build rich Android UI with drag and drop.
Visualize your UI on tablets, phones, and other devices. Switch themes,
locales, even platform versions instantly, without building.
Visual refactoring lets you extracts layout for inclusion, convert layouts,
extract styles.
Editor support for working with custom UI components
On-device Developer Options
Enable debugging over USB.
Quickly capture bug reports onto the device.
Show CPU usage on screen.
Draw debugging information on screen such as layout bounds, updates on
GPU views and hardware layers, and other information.
Plus many more options to simulate app stresses or enable debugging
options.
To access these settings, open the Developer options in the systemSettings. On Android 4.2 and higher, the Developer options screen is
hidden by default. To make it available, go toSettings > About phone and
tap Build numberseven times. Return to the previous screen to find
Developer options.
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
9/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 9
Fig. 1. 1 Developer Options
Develop on Hardware Devices
Use any commercial Android hardware device or multiple devices.
Deploy your app to connected devices directy from the IDE.
Live, on-device debugging, testing, and profiling.
Develop on Virtual Devices
Emulate any device. Use custom screen sizes, keyboards, and other
hardware components.
Advanced hardware emulation, including camera, sensors, multitouch,
telephony.
Develop and test for broad device compatibility.
Powerful Debugging
Full Java debugger with on-device debugging and Android-specific tools.
Built-in memory analysis, performance/CPU profiling, OpenGL ES tracing.
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
10/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 10
Graphical tools for debugging and optimizing UI, runtime inspecton of UI
structure and performance.
Runtime graphical analysis of your app's network bandwidth usage.
Testing
Fully instrumentated, scriptable test environment.
Integrated reports using standard test UI.
Create and run unit tests on hardware devices or emulator.
Native Development
Support for compiling and packaging existing code written in C or C++.
Support for packaging multiple architectures in a single binary, for broad
compatibility.
.
C. Evaluation
1. What you must prepare for android development ?
Operating System
Android SDK
JDK
Bigger and Brighter Mobile Screen
Much Money
2. What would motivate you to write programs for mobile devices ?
the challenge of writing optimized applications
new learning experience
fun factor
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
11/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 11
D. Practical Guide
1. Tools and Materials
a. Laptop (Min Dual Core 1,8 GHz , Memory 2GB)
b. Java SDK 1.7c. ADT-Bundle
d. Tablet (Min 512 RAM)
2. Work steps
1) Setup eclipse with ADT Plugin
1) Start Eclipse, if its not already running.
2) Choose HelpInstall New Software.The Install window pops up (see Figure 2-19). This window allows you to install
new plug-ins in Eclipse.
3) Click the Add button to add a new site that will display the Add
Repository window (see Figure).
Sitesare the Web addresses where the software is hosted on the Internet. dding a
site to Eclipse makes it easier for you to update the software when a ew version
is released
Fig. 1. 2 Repository Window
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
12/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 12
4) Type a name in the Name field.
I recommend using Android ADT, but it can be anything you choose.
5) Type https://dl-ssl.google.com/android/eclipse/in the Location
field.
Fig. 1. 3 Add Repository
6) Click the OK button.
Android ADT is selected in the Work With drop-down menu, and the
available options are displayed in the Name and Version window of the
Install Details dialog box.
7) In the Install dialog box, select the check box next to Developer
Tools, and click the Next button (see Figure Below).
Fig. 1. 4 Developer Tools
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
13/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 13
The Install Details dialog box should list both the Android Dalvik Debug
Monitor Server (DDMS; see Get physical with a real Android device,
later in this chapter) and the ADT.
Fig. 1. 5 Install Details
8) Click the Next button to review the software licenses.
9) Click the Finish button.
10)When youre prompted to do so, click the Restart Now button to
restart Eclipse.
The ADT plug-in is installed.
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
14/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 14
b. Liner Layout
A layout that arranges its children in a single row
1) Step 1 (Horizontal Layout)
Run eclipse,choose File > New > Android Project.
2) Step 2
Fill the new box dialogue with these datas.
Fig. 1. 6 LinearLayout1
Click Next.
Fig. 1. 7 Create Activity LinearLayout1
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
15/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 15
Click Next.
Fig. 1. 8 Launcher LinearLayout1
Click Next.
Fig. 1. 9 Blank Activity LinearLayout1
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
16/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 16
Click Next.
Fig. 1. 10 Activity Name LinearLayout1
Click Finish.
3) Step 3
Choose LinearLayout1 /res/layout/activity_linear_layout1.xml
Fig. 1. 11 Activity LinearLayout1 XML
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
17/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 17
4) Step 4
Type these codes. Although it is too long, for right now you just need to
write one pattern, just copy-paste-Edit.
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
18/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 18
android:text="Blue" />
5) Step 5
Layout activity_linear_layout1.xml, if we see this from its hierarky
from outline style. It will appear like this
Fig. 1. 12 OutLine LinearLayout1
6) Step 6
Open LinearLayout1.java , see figure below.
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
19/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 19
Fig. 1. 13 LinearLayout1.java
and Run Program with shortcut CTRL+F11 or right click and choose
package > run as > android Project.
7) Step 7
You will See the result like this
Fig. 1. 14 Output LinearLayout1
8) Step 1 (Vertical Layout)
Run eclipse,choose File > New > Android Project.
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
20/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 20
9) Step 2
Fill the new box dialogue with these datas.
Fig. 1. 15 New App LinearLayout2
Click Next.
Click Next.
Click Next.
Click Next.
Fig. 1. 16 Activity Name LinearLayout2
Click Finish.
10)Step 3
Open LinearLayout2 /res/layout/activity_linear_layout2.xml
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
21/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 21
Fig. 1. 17 LinearLayout2 XML
11)Step 4
Type these codes. Although it is too long, for right now you just need to
write one pattern, just copy-paste-Edit.
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
22/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 22
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
23/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 23
12)Step 5
Layout activity_linear_layout2.xml, if we see this from its hierarky
from outline style. It will appear like this
Fig. 1. 18 OutLine LinearLayout2
13)Step 6
Open LinearLayout2.java , see figure below.
Fig. 1. 19 LinearLayout2.java
and Run Program with shortcut CTRL+F11 or right click and choose
package > run as > android Project.
14)Step 7
You will See the result like this
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
24/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 24
Fig. 1. 20 Output Program LinearLayout2
c. Relative Layout
RelativeLayout is a layout where the position of components
symbol,text,etc) can be managed and placed in front of other components.
For example OKbutton can be placed under Editext , the Cancel
button can be placed on the left side of OK button and under Edittext.
The main consept is that it has connection between one button and
another.
1) Step 1
Run eclipse,choose File > New > Android Project.
2) Step 2
Fill the new box dialogue with these datas.
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
25/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 25
Fig. 1. 21 New App RelativeLayout1
Click Next.
Click Next.
Click Next.
Click Next.
Fig. 1. 22 Activity Name RelativeLayout1
Click Finish.
3) Step 3
Open RelativeLayout1
/res/layout/activity_relative_layout1.xml
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
26/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 26
Fig. 1. 23 RelativeLayout1 XML
4) Step 4
Type these codes. Although it is too long, for right now you just need to
write one pattern, just copy-paste-Edit.
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
27/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 27
5) Step 5
Layout activity_relative_layout1.xml, if we see this from its hierarky
from outline style. It will appear like this
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
28/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 28
Fig. 1. 24 Outline RelativeLayout1
6) Step 6
Open RelativeLayout1.java , see figure below.
Fig. 1. 25 RelativeLayout1.java
and Run Program with shortcut CTRL+F11 or right click and choose
package > run as > android Project.
7) Step 7
You will See the result like this
Fig. 1. 26 Output program RelativeLayout1
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
29/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 29
d. Table Layout
A layout that arranges its children into rows and columns.
1) Step 1
Run eclipse,choose File > New > Android Project.
2) Step 2
Fill the new box dialogue with these datas.
Fig. 1. 27 New App TableLayout1
Click Next.Click Next.
Click Next.
Click Next.
Fig. 1. 28 Activity Name TableLayout1
Click Finish.
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
30/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 30
3) Step 3
Open TableLayout1 /res/layout/activity_table_layout1.xml
Fig. 1. 29 TableLayout1 XML
4) Step 4
Type these codes. Although it is too long, for right now you just need to
write one pattern, just copy-paste-Edit.
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
31/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 31
android:gravity="right"
android:padding="3dp"/>
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
32/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 32
android:text="X Import..." />
5) Step 5
Layout activity_table_layout1.xml, if we see this from its hierarky
from outline style. It will appear like this
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
33/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 33
Fig. 1. 30 OutLine TableLayout1
6) Step 6
Open TableLayout1.java , see figure below.
Fig. 1. 31 TableLayout1.java
and Run Program with shortcut CTRL+F11 or right click and choose
package > run as > android Project.
7) Step 7
You will See the result like this
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
34/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 34
Fig. 1. 32 Output Program TableLayout1
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
35/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 35
e. Image
In this step, you added the ImageViewinside your program. An
ImageViewallows you to project an image to the devices screen.
1) Step 1
Run eclipse,choose File > New > Android Project.
2) Step 2
Fill the new box dialogue with these datas.
Fig. 1. 33 New App Image1
Click Next.
Click Next.
Click Next.
Click Next.
Fig. 1. 34 Activity Name Image1
Click Finish.
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
36/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 36
3) Step 3
Open Image1 /res/layout/activity_image1.xml
Fig. 1. 35 Image1 XML
4) Step 4
Create a folder with name drawable , in Image1/res/ folder. Like this
picture.
Fig. 1. 36 Drawable folder on Image1
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
37/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 37
5) Step 5
Prepare your image that you want to display. For example
trilateral.png.
And copy to folder drawable , so you can see like this
Fig. 1. 37 Copy trilateral.png to drawable folder
6) Step 6
Type these codes. Although it is too long, for right now you just need to
write one pattern, just copy-paste-Edit.
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
38/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 38
android:layout_width="278dp"
android:layout_height="355dp"
android:src="@drawable/trilateral" />
7) Step 5
Layout activity_image1.xml, if we see this from its hierarky from
outline style. It will appear like this
Fig. 1. 38 Outline Image1
8) Step 6
Open Image1.java , see figure below.
Fig. 1. 39 Image1.java
and Run Program with shortcut CTRL+F11 or right click and choose
package > run as > android Project.
You will see the result like this .
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
39/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 39
Fig. 1. 40 Output Image1 Program
9) Step 7
Click on this image on your emulator.
Fig. 1. 41 Menu Image
,
You will see your program and the others program Like this
Fig. 1. 42 Application on Android
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
40/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 40
10) Step 8
Prepare an Image for your icon , forexample icon.png.
Fig. 1. 43 Icon.png
Copy icon.png to drawable folder.
Fig. 1. 44 Copy icon.png to drawable folder
11) Step 9
Open file/Image1/AndroidManifest.xml ,
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
41/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 41
Fig. 1. 45 AndroidManifest.xml
12) Step 10
Change this line :
android: icon="@drawable/ ic_launcher"
Like this :
android: icon="@drawable/ icon"
13) Step 11
Run your application , click this image
Fig. 1. 46 Menu Image
You will see in your application icon like this
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
42/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 42
Fig. 1. 47 Application on Android
f. Text Auto Complete
1) Step 1 (Horizontal Layout)
Run eclipse,choose File > New > Android Project.
2) Step 2
Fill the new box dialogue with these datas.
Fig. 1. 48 New App TextAuto1
Click Next.
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
43/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 43
Click Next.
Click Next.
Click Next.
Fig. 1. 49 Activity Name TextAuto
Click Finish.
3) Step 3
Open TextAuto1 /res/layout/activity_text_auto1.xml
Fig. 1. 50 TextAuto XML
4) Step 4
Type these codes. Although it is too long, for right now you just need to
write one pattern, just copy-paste-Edit.
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
44/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 44
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
45/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 45
5) Step 5
Layout activity_text_auto1.xml, if we see this from its hierarky from
outline style. It will appear like this
Fig. 1. 51 Outline TextAuto
6) Step 6
Open TextAuto1/res/values/str ing.xml, edit like this :
Make Text Auto Complete
Program
Fill with minimal 3 characterHello world!
7) Step 7
Open LinearLayout1.java , and change like this code :
packagecom.example.textauto1;
impor tandroid.os.Bundle;
impor tandroid.app.Activity;
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
46/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 46
impor tandroid.graphics.Color;
impor tandroid.view.Menu;
impor tandroid.text.Editable;
impor tandroid.text.TextWatcher;
impor tandroid.widget.ArrayAdapter;
impor tandroid.widget.AutoCompleteTextView;
impor tandroid.widget.TextView;
publ icclassTextAuto1 extendsActivityimplementsTextWatcher{
TextView result;
AutoCompleteTextView edit;
String[] item = { "Indonesia", "China", "Japan", "Qatar",
"Germany","Singapura", "Filipina", "Kamboja", "Brunei
Darussalam", "Timor Leste","Myanmar", "Thailand", "Malaysia","India" };
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(android.R.style.Theme_Light);
setContentView(R.layout.activity_text_auto1);
result = (TextView)findViewById(R.id.m_result);
edit = (AutoCompleteTextView)findViewById(R.id.auto_edit);
edit.addTextChangedListener(th is);
edit.setAdapter(newArrayAdapter(th is,
android.R.layout.simple_list_item_1, item));
edit.setTextColor(Color.BLACK);
}
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
47/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 47
@Override
publ icbooleanonCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate(R.menu.text_auto1, menu);
returnt rue;
}
@Override
publ icvoidafterTextChanged(Editable s) {
//TODOAuto-generated method stub
}
@Override
publ icvoidbeforeTextChanged(CharSequence s, in tstart, in tcount,
in tafter) {
//TODOAuto-generated method stub
}
@Override
publ icvoidonTextChanged(CharSequence s, in tstart, in tbefore, in t
count) {
//TODOAuto-generated method stub
result.setText(edit.getText());
}
}
and Run Program with shortcut CTRL+F11 or right click and choose
package > run as > android Project.
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
48/49
Myanmar Vocational Teacher Training/ module compilation guidance/ batch 3/ 2013 Page 48
8) Step 7
You will See the result like this
Fig. 1. 52 Output Program Text Auto
-
7/29/2019 Chapter 1 - Introduction to Android.pdf
49/49
E. Assigment
Implement any/all of the following projects using simple text boxes (EditText,
TextView) and buttons :
Create Common Calculator
Fig. 1. 53 Assignment Calculator
Change your calculator icon to this image