LAB 2 Hello Toast
LAB 2 Hello Toast
MOBILE APPLICATION
WHAT YOU WILL LEARN
Start Android Studio and create a new project with the following parameters:
TASK 2: ADD VIEWS TO "HELLO TOAST" IN THE LAYOUT EDITOR
In this task, you will create and configure a user interface for the "Hello Toast" app by
arranging view UI components on the screen.
Why: Every app should start with the user experience, even if the initial
implementation is very basic.
Views used for Hello Toast are:
TextView - A view that displays text.
Button - A button with a label that is usually associated with a click handler.
LinearLayout - A view that acts as a container to arrange other view. This type of
view extends the ViewGroup class and is also called a view group. LinearLayout is a
basic view group that arranges its collection of views in a horizontal or vertical row.
2.2 CHANGE THE VIEW GROUP TO A LINEARLAYOUT
A vertical linear layout is one of the most common layouts. It is simple, fast, and always a good
starting point. Change the view group to a vertical, LinearLayout as follows:
In the Component Tree pane (7 in the previous screenshot), find the top or root view directly below
the Device Screen.
Click the Text tab (8) to switch to the code view of the layout.
In the second line of the code, change the root view group to LinearLayout. The second line of code
now looks something like this:
<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
In this task you will delete the current TextView (for practice),
and add a new TextView and two buttons to the LinearLayout as shown
in the UI sketch for this task. Refer to the UI diagram above, if necessary.
To change the layout to be vertical, add the following code inside
LinearLayout, below android:layout_height
android:orientation="vertical"
ADD AN ONCLICK PROPERTY TO A BUTTON
A click handler is a method that is invoked when the user clicks on a user interface element. In Android, you can
specify the name of the click handler method for each view in the XML layout file with the
android:onClick
1. Open res/layout/activity_main.xml.
2. Add the following property to the button_toast button.
android:onClick="showToast“
3. Add the following attribute to the button_count button
android:onClick="countUp"
4. Inside of activity_main.xml, place your mouse cursor over each of these method names.
5. Press Alt-Enter (Option-Enter on the Mac), and select Create onClick event handler.
6. Choose the MainActivity and click OK.
ADD IN MAINACTIVITY.JAVA
in onCreate():
CountUp Method:
CREATE A VIRTUAL DEVICE
Use emulators to test app on different versions of Android and form factors.
16
CONFIGURE VIRTUAL DEVICE
17
RUN ON A VIRTUAL DEVICE
18
RUN ON A PHYSICAL DEVICE
Windows drivers:
● OEM USB Drivers
19
GET FEEDBACK AS YOUR APP RUNS
20
LOGGING
import android.util.Log;
21
ANDROID MONITOR > LOGCAT PANE
22
SUMMARY
Create a scoring app for your favorite team sport. Make the
background an image that represents that sport. Create buttons
to count the scores for each team.