Professional Documents
Culture Documents
Secondary 1 ICT
Mobile App Development – Ch.2 Basics
Name: _________________________________ Class: ___________ ( )
Label
Slider
Screen
Button
CheckBox
Each component (including a Screen) has its own properties, shown on the panel on
the right in App Inventor.
Properties of
the selected
component
In selection
List of all
components
To add a new component to a Screen, drag the component from the Palette to the
Viewer.
Renaming Components
Each component in the app has a unique name.
It will be very hard to identify the components during coding if you leave
them with the default numeric names.
Always rename the components with a consistent set of short and
meaningful names!
Component names can contain only letters, numbers and underscores
and must start with a letter or an underscore.
To rename a component, select the component and click Rename in
the Components panel of the Designer view.
Checkpoint
How will you name these components?
Name it here Good examples
Basic Input/Output
To program our app, we go to the Blocks page in App Inventor.
There are built-in blocks and blocks for each component on the Blocks page on the left.
Add the Color block from the section.
Screen1.BackgroundColor means the BackgroundColor property of Screen1.
>
Checkpoint
This time when Button1 is clicked, the background colour of Button1 should turn yellow.
Complete the program.
Add the text string block from the section. Type the text you want to
display in the block.
Example: Capture Text Entered in a TextBox and Display in a Label
When Button_OK is
clicked, change the
display text of
Label_name to the text
entered in
TextBox_name.
obtains the text entered by the user in TextBox_name.
TextBoxes with white BackgroundColor may not be clearly visible on iOS/iPadOS. It
is recommended to set the LightGrey BackgroundColor instead.
TextBoxes by default has a hint text. It can be removed by clearing the Hint property.
🔨 Practical 2
Make a simple program that shows the message “hello world” when a button is clicked.
Step 1. Creating the User Interface
Set the title of the Screen to be “Ch.2 Practical 2”. Drag a Button and a Label and
position them like this:
Change the display text of the Button to “Click me” and the display text of the Label to
nothing:
Rename the Button and the Label with proper component names. How do you call
them?
🔨 Practical 3
Import S1_Ch2_CatDog.aia. The project contains 2 images in the media library:
Complete the app such that when the “cat” or “dog” button is clicked, the correct
background image will display accordingly.
Step 1. Creating the User Interface
Drag two buttons and place them as shown above. Change the display text of the
buttons to “Cat” and “Dog”.
Rename the Buttons with proper component names. How do you call them?
Step 2. Coding
Go to the “Blocks” page and finish the following code.
Hint: When the cat button is clicked, we change the BackgroundImage property of the
Screen to be the file name of the cat image (cat.jpg).
unpredictable, e.g. user inputs) text, we can use the block ( section) to
combine them to form a meaningful sentence.
When Button_OK is
clicked, show a message
dialog “Hi [what has
been typed in
TextBox_name]” with
“Hello” as the title and
“OK” as the button.
Step 1. Creating the User Interface
Prepare the user interface as shown above. What do we need?
Set the BackgroundColor of the TextBox to be grey to improve readability. Remove
the Hint text.
Rename with proper component names. How do you call them?
Step 2. Coding
Go to the “Blocks” page and finish the following code.
Performing Calculations
We use the blocks in to do calculations. These blocks will fit into other blocks such
as those of a Notifier or a Label.
A number value
Addition, subtraction,
multiplication and division
Rounding to the nearest
integer
Format with decimal places
(12+20) ÷ 8 Result:
The message should be “Your BMI is XX.”, where XX is the calculation result.
Step 2. Coding
Go to the “Blocks” page and finish the following code. Optionally, you may use
to shorten your code.
⑤
Hint: To have 3 inputs in the join block, click the blue gear icon on the join block and
drag more “string” to “join”.
💡 Debugging Exercise
1. In one of the students’ BMI app (Practical 5), the result shows:
2. We want to obtain the height in cm from the textbox TBox_cm and convert it into
metres after clicking the button Button_cal. The result should be shown in the
label Label_m.
When attaching the block of TBox_cm, it cannot be attached and we see the
following message. What is the mistake here?
References
Mobile CS Principles – https://course.mobilecsp.org
MIT App Inventor – http://appinventor.mit.edu
End