The Content helps those who wish to program mobile applications using android platform. The content has been used to conduct mobile application boot camps using android platform on different regions in Tanzania
4. Before using eclipse and android SDK, you
need to check that the Android Developer
Tools are set and corresponds to android
SDK is set directory correctly.
See next slide
9. Click file – New – Android project.
Enter the project name.
Select an Emulator to use
Enter application name
Package name – e.g com.emobilis – two
sections*
Activity name
10. Naming
Project Name
Application Name
Package Name
Min SDK
Target SDK
Manifest Files
Resource files
R file
Emulator
15. An Activity is an application component that
provides a screen with which users can
interact in order to do something.
Such as dial the phone, take a photo, send an
email, or view a map.
Each activity is given a window in which to
draw its user interface.
16.
17. All activities will implement onCreate(Bundle) to
do their initial setup.
onCreate() You must implement this method. The
system calls this when creating your activity.
Within your implementation, you should initialize
the essential components of your activity.
Most importantly, this is where you must
call setContentView() to define the layout for the
activity's user interface
18.
/* AUTO-GENERATED FILE. DO NOT MODIFY. This class was automatically generated by the
* aapt tool from the resource data it found. It should not be modified by hand. */
package cs454.demo;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class id {
public static final int textview=0x7f050000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
19. What is a Resource File?
A resource file may contain a collection of
icons, xml files for UI design, strings files etc.
In android, UI design is constructed in xml
files located in res – layout.
Include drawable – use it for images, icons
21. The next xml Files shows a TextView with a
linear layout.
Linear layout allows a developers to arrange
UI components in a vertical or horizontal
manner.
A TextView shows text that can be edited –
it’s a label.
23. Android Provides several UI components including
TextViews
EditText
TextArea
RadioButton
CheckBox
List
Buttons
Tabs
Menus
Etc
We look on each UI component individually
24. Displays text to the user and optionally
allows them to edit it.
A TextView is a complete text editor,
however the basic component is configured
to not allow editing.
In order to edit EditText for a subclass that
configures the text view for editing.
25.
26.
27.
28.
29. Accessing our TextView from the android
code.
We use the id to do this;
So, in android we add;
EditText t = (EditText)findViewById(R.id.txtUser);
30.
31. Allows you to separate your UI with the code
that is controlling.
Allows developers arrange the java codes
easily
Easy understanding of the Java programming
in android
32. EditText is a thin veneer over TextView that
configures itself to be editable.
<EditText
android:id = "@+id/txtUser"
android:layout_width="100px"
android:layout_height="198dp"
android:gravity="center“
/>
33. Represents a push-button widget. Push-
buttons can be pressed, or clicked, by the
user to perform an action
<Button
android:id = "@+id/btnRegister"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Register“
/>
34.
35. Edit Text can also be used to input long text,
recall , text areas.
This can be done by setting the layout width
and height to defined pixels
<EditText
android:id = "@+id/txtComment"
android:layout_width="200px"
android:layout_height="200px"
android:gravity="center“
/>
36. Accessing the Edit Text from the android code –
(Our activity)
We use findViewById method to refer from the R
directory.
EditText tComment = (EditText)findViewById(R.id.txtComment);
37. A radio button is a two-states button that can
be either checked or unchecked.
When the radio button is unchecked, the user
can press or click it to check it.
However, contrary to aCheckBox, a radio
button cannot be unchecked by the user once
checked.
38. Radio buttons are normally used together in
a RadioGroup.
When several radio buttons live inside a radio
group, checking one radio button unchecks
all the others.
42. Accessing the Radio Buttons from the android
code – (Our activity)
We use findViewById method to refer from the R
directory.
RadioButton tComment =
(RadioButton)findViewById(R.id.rdPhone);
//second Radio
RadioButton tComment =
(RadioButton)findViewById(R.id.rdEmail);
43. Quickview
A toast is a message that appears on the
surface of the screen for a moment, but it
does not take focus (or pause the current
activity).
so it cannot accept user input
You can customize the toast layout to include
images
44. A toast notification is a message that pops up
on the surface of the window.
It only fills the amount of space required for
the message and the user's current activity
remains visible and interactive.
The notification automatically fades in and
out, and does not accept interaction events.
The screenshot below shows an example
toast notification from the Alarm application.
47. Add android:onClick attribute on the radio
buttons in your xml file.
<RadioButton
android:id="@+id/radio_red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red"
android:onClick="onRadioButtonClicked"/>
48. Include this method in your activity – Note this
method shares the same name with on Click
attribute in your xml.
//on click event in radio Buttons
public void onRadioButtonClicked(View v)
{
// Perform action on clicks
RadioButton rb = (RadioButton) v;
Toast.makeText(Hello.this, rb.getText(),
Toast.LENGTH_SHORT).show();
}
49. A checkbox is a specific type of two-states
button that can be either checked or
unchecked.
A example usage of a checkbox inside your
xml would be the following.
50. Include this in your xml
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="check it out“
android:onClick="onCheckboxClicked"
>
Note: onClick attribute
51. Include this in your activity
public void onCheckboxClicked(View v) {
// Perform action on clicks, depending on whether it's now checked
if (((CheckBox) v).isChecked()) {
Toast.makeText(Hello.this, "Selected",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(Hello.this, "Not selected",
Toast.LENGTH_SHORT).show();
}
}
64. Creating from resource images
A simple way to add graphics to your
application is by referencing an image file
from your project resources.
Supported file types are PNG (preferred), JPG
(acceptable) and GIF (discouraged).
This technique would obviously be preferred for
application icons, logos, or other graphics such as
those used in a game