You are on page 1of 114

College of Computing Studies

 Mobile Development

Mobile Development or Mobile Application Development is the creation of software intended to run on mobile devices.
Hence, the mobile development process involves creating installable software bundles (code, binaries, assets, etc.),
implementing backend services such as data access with an API, and testing the application on target devices.

 API (Application Programming Interface)

API allows applications or software to communicate with each another. It is a set of functions that allows applications to
access data and interact with external software components, operating systems, or micro services.

 Types of Mobile Application Development

1. Native Applications - refer to building a mobile app exclusively for a single platform. The app is built with
programming languages and tools that are specific to a single platform.

2. Web Applications - refer to applications for mobile devices that require only a Web browser to be installed on the
device. They use Web technologies and are not limited to the underlying platform for deployment.

3. Hybrid Applications - are software applications that combine elements of both native apps and web applications.

 Types of Mobile Operating System

1. Android OS (Google Inc.) - developed by Google to be primarily used for touchscreen devices, cell phones, and
tablets.

JBQ@2021
College of Computing Studies

2. IPhone OS / IOS (Apple) - Apple’s iPhone OS was originally developed for use on its iPhone devices. Now, the
mobile operating system is referred to as iOS and is supported on a number of Apple devices including the iPhone,
iPad, iPad 2 and iPod Touch. The iOS mobile operating system is available only on Apple’s own manufactured devices
as the company does not license the OS for third-party hardware. Apple iOS is derived from Apple’s Mac OS X
operating system.

3. BADA (Samsung Electronics) - Bada is a proprietary Samsung mobile OS that was first launched in 2010. The
Samsung Wave was the first smartphone to use this mobile OS. Bada provides mobile features such as multipoint-
touch, 3D graphics and of course, application downloads and installation.

4. BLACKBERRY OS (RESEARCH IN MOTION) - is a proprietary mobile operating system developed by Research


In Motion for use on the company s popular BlackBerry handheld devices.

 Android

Android is an open source and Linux-based Operating System for mobile devices such as smartphones and tablet
computers. Android was developed by the Open Handset Alliance, led by Google, and other companies.

 Software Development Kit (SDK)

Software Development Kit (SDK) is a collection of software development tools in one installable package. They facilitate
the creation of applications by having a compiler, debugger and perhaps a software framework.

 Android SDK

The Android software development kit (SDK) includes a comprehensive set of development tools. These include a
debugger, libraries, a handset emulator based on QEMU, documentation, sample code, and tutorials.

 Java Development Kit

JBQ@2021
College of Computing Studies

The Java Development Kit (JDK) is a software development environment used for developing Java applications and
applets. It includes the Java Runtime Environment (JRE), an interpreter/loader (java), a compiler (javac), an archiver (jar),
a documentation generator (javadoc) and other tools needed in Java development.

Prepared by:

Joel B. Quiambao

Instructor1

JBQ@2021
College of Computing Studies

 History of Android

Android Inc. was founded in Palo Alto, California, in October 2003 by Andy Rubin, Rich
Miner, Nick Sears, and Chris White. Rubin described the Android project as having
"tremendous potential in developing smarter mobile devices that are more aware of its
owner's location and preferences". The early intentions of the company were to develop
an advanced operating system for digital cameras, and this was the basis of its pitch to
investors in April 2004.

In 2004 the project changed to become an operating system for smartphones. Android
Inc., was bought by the American search engine company Google Inc., in 2005. At
Google, the Android team decided to base their project on Linux, an open source
operating system for personal computers.

On November 5, 2007, Google announced the founding of the Open Handset Alliance,
a consortium of dozens of technology and mobile telephone companies, including Intel
Corporation, Motorola, Inc., NVIDIA Corporation, Texas Instruments Incorporated, LG
Electronics, Inc., Samsung Electronics, Sprint Nextel Corporation, and T-Mobile
(Deutsche Telekom). The consortium was created in order to develop and promote
Android as a free open source operating system with support for third-party
applications. Android-based devices use wireless networks in order to take full
advantage of features such as one-touch Google searches, Google Docs (e.g., word
editors, spreadsheets), and Google Earth (satellite mapping software).

The first cellular telephone to feature the new operating system was the T-Mobile G1,
released on October 22, 2008. In 2012 Android became the most popular operating
system for mobile devices, surpassing Apple’s iOS, and, as of 2020, about 75 percent
of mobile devices run Android.

JBQ@2021
College of Computing Studies

Android versions, name, and API level

Code name Version numbers API level Release date

No codename 1.0 1 September 23, 2008

No codename 1.1 2 February 9, 2009

Cupcake 1.5 3 April 27, 2009

Donut 1.6 4 September 15, 2009

Eclair 2.0 - 2.1 5-7 October 26, 2009

Froyo 2.2 - 2.2.3 8 May 20, 2010

JBQ@2021
College of Computing Studies

Gingerbread 2.3 - 2.3.7 9 - 10 December 6, 2010

Honeycomb 3.0 - 3.2.6 11 - 13 February 22, 2011

Ice Cream Sandwich 4.0 - 4.0.4 14 - 15 October 18, 2011

Jelly Bean 4.1 - 4.3.1 16 - 18 July 9, 2012

KitKat 4.4 - 4.4.4 19 - 20 October 31, 2013

Lollipop 5.0 - 5.1.1 21- 22 November 12, 2014

Marshmallow 6.0 - 6.0.1 23 October 5, 2015

Nougat 7.0 24 August 22, 2016

Nougat 7.1.0 - 7.1.2 25 October 4, 2016

Oreo 8.0 26 August 21, 2017

Oreo 8.1 27 December 5, 2017

Pie 9.0 28 August 6, 2018

Android 10 10.0 29 September 3, 2019

Android 11 11 30 September 8, 2020

1. Android 1.0: Alpha (API 1)

The initial version of Android was released on September 23, 2008, known as Android
1.0. There were many loopholes in this alpha version including the necessity of physical
keyboards or hardware buttons. It has an android API (application program interface)
level 1. API level is the integer value that identifies the API framework revision provided
by the version of the android platform. API framework includes the core set of classes,
packages, XML elements, intents, and permissions that the application can request.

JBQ@2021
College of Computing Studies

Features

Google Maps, browser, calendar

Camera and scroll down the notification bar

Gmail integration, Contacts, and Google Synchronization.

Wireless supports – Wi-Fi and Bluetooth.

2. Android 1.1: Beta (API 2)

Android Beta version was released on February 9, 2009, with API changes and
resolved issues encountered in 1.0. This android version was released for T-Mobile G1
devices only.

JBQ@2021
College of Computing Studies

Features

Display details and reviews for locations

Add Save attachment in the message

Provide detailed information by clicking on the business

3. Android 1.5: Cupcake (API 3)

It was released on April 30, 2009, with the first official public code name and amazing
features as compared to the old versions. Moreover, it also brought the third-party app
widgets that was the most distinguishing and valuable feature.

JBQ@2021
College of Computing Studies

Features

on-screen keyboard and search function

Uploading videos and images

Copy and paste facility and video recordings

Support for MPEG4 and 3GP formats

4. Android 1.6: Donut (API 4)

The android 1.6 version was released on September 15, 2009, was many valuable
changes including the ability to operate on a number of different screen resolutions and
sizes. Donut provides the voice and text entry search including bookmark history, and
the ability to select multiple images for deletion.

JBQ@2021
College of Computing Studies

Features

Power Control widget for handling Wi-Fi, Bluetooth, GPS, etc.

Gallery and Camera quick toggling features

WVGA screen resolution speed

Technology support for CDMA/EVDO, 802.1x, VPNs, and a text-to-speech engine

Speed improvements for camera and searching applications

Quick Search Box

5. Android 2.0: Eclair (API 5)

Éclair 2.0 – 2.1 was released on December 3, 2009, with multiple account
synchronizations of email and contacts. Moreover, there are many new features were
added including flash support, scene mode, white balance, color effect, macro focus
and digital zoom. Android 2.1 version brought bug fixes and stability improvements to
the Éclair. The most valuable feature was real-time traffic information and voice-guided
turn by turn navigation.

JBQ@2021
College of Computing Studies

Features

Update UI

Support Bluetooth 2.1

Improve Google map

Minor API Changes

Support Live and animated Wallpapers

Ability to add contact’s photo and select to call, message or email

6. Android 2.2: Froyo (API 8)

Android version 2.2 was released on May 20, 2010, with speed, memory, and
performance improvements. It was introduced with the enhanced Bluetooth functionality
and compatibility with docks, portable WiFi hotspot for sharing the 3G connection.
Google Nexus One was the first smartphone having an android 2.2 android version.
Android version list provides you the complete historical knowledge of android operating
system updates and improvements.

JBQ@2021
College of Computing Studies

Features

Support for Animated GIF and multiple keyboard languages

Speed and performance improvements

Upload file support in the browser

Support numeric & alphanumeric passwords to enhance security

Increased Compatibility with car kits and headsets

Wi-Fi Support Hotspot functionality

7. Android 2.3: Gingerbread (API 9)

Gingerbread exists in the 7th position in the android version list that was released on
December 6, 2010. The main enhanced feature was the introduction of gaming API with
improved graphical intense gaming, so it has boomed the mobile games.

JBQ@2021
College of Computing Studies

Features

Improve Copy and Paste Facility

Updated UI design

Support for VP8 and WebM video format

Video calling and Social Networking Supports

Easy to use a keyboard with faster and intuitive typing

8. Android 3.0: Honeycomb (API 11)

Honeycomb from the android version list was released in 2011 that was tablet-only
release to launch the Motorola Xoom. It was also suitable for those mobiles having a
larger view than current smartphones.

Features

Gmail, contacts, camera and gallery improvements

Support for passwords with complex characters

encrypted storage and updated 3D UI

Supports multiprocessors and recent apps for easy visual multitasking

JBQ@2021
College of Computing Studies

Media Sync from SD Card

Action bar for application control

System bar for global status and notifications

Google eBooks and Talk Video Chat

Support Adobe Flash in Browser

More sensor support

High-performance Wi-Fi Connections and Lock

Chinese handwriting and redesigned keyboard

9. Android 4.0: Ice Cream Sandwich (API 14)

The ice cream sandwich was released on October 19, 2011, with many enhanced
features to enter the era of modern design. The snapshot was introduced to take
screenshots by holding the volume and power button. Android version list has a variety
of android operating systems but as compared to all older versions, ice cream sandwich
widgets are more robust and resizable.

Features

Spelling check feature

JBQ@2021
College of Computing Studies

Wi-Fi direct

Photo Decor facility and on-screen buttons

Unlocking with face-fixing.

Card-like appearance for app-switching

Improved video recording with high resolution

Better Camera performance

Ability to open up to 16 tabs in the web browser

10. Android 4.1: Jelly Bean (API 16)

The better version of android known as Jelly Bean was released in June 2012 with
Google Digital Assistant technology accessible from the home screen. The spectacular
predictive intelligence utility provides expandable and interactive notifications.
Moreover, users can enjoy the multi-user support into play and many other valuable
features.

Features

Voice search and typing

Panorama

JBQ@2021
College of Computing Studies

Project Butter

Expandable notifications

Daydream as a screensaver

Power control

Support USB audio

Improved camera app

Security improvements

New gestures and accessibility features

Multiple user accounts (Only for tablets)

4k resolution support

Supporting Bluetooth with low energy

Bi-directional text and different language support

Set or adjust the volume of incoming calls and show a message alert

Google displays relevant content based on your search history

Native emoji support

11. Android 4.4: KitKat (API 19)

Android version 4.4 was released on September 3, 2013, with more focused on better
user experience. KitKat is optimized to run at a larger range of old versions from the
android version list. The smartphone must have a minimum of 512 MB of RAM.

JBQ@2021
College of Computing Studies

Features

Screen Recording

Contact Prioritization

GPS Support

Smarter Caller ID

Offline music support

UI updates for alarm and google map navigations

Cartoonish ideograms and emojis to the Google keyboard

KitKat has ‘OK Google’ feature that allows access to Google to the users without
touching your smartphones.

12. Android 5.0: Lollipop (API 21)

Lollipop or android version 5.0 was released on November 12, 2014, with a redesigned
user interface and built with “material design”. It gives a new and modern look extended
across all of android, applications, and google products. Lollipop from the android
version list comes with many amazing features including Support for better notification
management.

JBQ@2021
College of Computing Studies

Features

Support ART

Better device protection

Notifications can be flicked away from the lock screen

Better and improved UI

Built-in battery saver feature

New material design

Revamped navigation bar

Support for Multiple sim cards

High definition of voice call.

13. Android 6.0: Marshmallow (API 23)

In the year 2015, Google used “Macadamia Nut Cookie” to describe android version 6.0
before the Marshmallow official announcement.

JBQ@2021
College of Computing Studies

Features

Support for Fingerprint readers

Type C USB support

Multi-window experience

’Sleep Mode’ for saving battery life

Clear permission system

Custom google tabs and improved Copy-pasting

14. Android 7.0: Nougat (API 24)

The android 7.0 was released in 2016 with a native split-screen mode, data saver
functionality, and a “bundled-by-app” system to organize notifications.

JBQ@2021
College of Computing Studies

Features

Provide multitasking and split-screen mode

Storage manager enhancements

Quick setting toggles

Display touch enhancements

Better setting application

Inline reply to messages and notifications without opening applications

15. Android 8.0: Oreo (API 26)

Oreo was released in the year 2017 having native picture-in-picture mode, notification
snoozing options and better control over how applications can alert you by notifications.

JBQ@2021
College of Computing Studies

Features

Password autofill

Auto-enable Wi-Fi

Downloadable fonts

Multi-display support

Support Picture-in-Picture

Notification channels and snooze notification

Google Play support and new emoji styling

Adaptive icons and smart text selection

16. Android 9: Pie (API 28)

The pie was publicly released on August 6, 2018, with plenty of amazing features
according to the users’ interests and requirements. According to a report, Pie is the
most widely used operating system in the android version list.

JBQ@2021
College of Computing Studies

Features

Sound amplifier with select to speak options

Artificial intelligence (AI) compatibility

Adaptive Battery and Brightness with background restrictions

Multi-camera support with the external camera compatibility

New Gesture Navigation and App Actions

New Screenshot Shortcut key and accessibility menu

Easier Screen Rotation and edge to edge screens support

Volume and Sound enhancements

Selectable Dark Mode

HDR, HD audio, multiple Bluetooth connections

Slices and long press to overview selection

Improved Security features for extra protection

Digital Wellbeing with app timers, dashboard and do not disturb options

Android backups and privacy enhancements

More Notification Information and easier text selection

JBQ@2021
College of Computing Studies

17. Android 10: Android Q (API 29)

Android version 10 is officially released on September 3, 2019, with enhanced features


and functionalities with higher API levels.

Features

Support for foldable smartphones with flexible displays

Dark mode for eyes comfortability

Navigation control over gesture quicker and intuitive ever

Sound amplifier with more clear sound

Smart reply suggestions for all messaging apps

Live caption for media playing on a smartphone

Undo app removal

Better notification control with many options

18. Android 11: (API 30)

Android developers are continually working to provide more advanced applications as


per the user requirements. Most of the developers are searching Android Developer vs
Web Developer to choose a trending field.

JBQ@2021
College of Computing Studies

The following are the new features that you will experience in the new android 11 that is
going to release and will be the latest version in the android version list.

Native screen recording

Muting notifications during video

Increase touch sensitivity

Notification History

Auto revoke app permissions

Following are the Revamped or updated features:

Revamped menu and screenshot shortcuts

New text selection mode from one app to another

Undoing recently cleared applications

Airplane mode doesn’t kill Bluetooth anymore

Face Unlock will require you to open your eyes in pixel 4

App pinning in the share menu

JBQ@2021
College of Computing Studies

Improved notification conversation shades

Conversation bubbles and context-aware dark mode

Improved one-time permissions

Android version 12

Google officially launched the final version of Android 12 in October 2021 and started rolling the
software out to its own Pixel devices soon after — alongside the launch of its new Pixel 6 and Pixel 6 Pro
phones.

In a twist from the last several Android versions, the most significant progressions with Android 12 are
mostly on the surface. Android 12 features the biggest reimagining of Android's interface since 2014's
Android 5.0 (Lollipop) version. That version, as we discussed a moment ago, was the first to showcase
Google's then-new Material Design standard. And this one is the first to integrate an updated and
completely overhauled take on that standard — something known as Material You.

Android 12 Beta

After a couple of Developer Preview releases, Android 12 Beta releases, with the first one on May 18th
this year as part of the Google I/O 2021 announcements. These Beta releases were a bit more polished,
and they gave us a fair idea of what the final OS release looks like. There were also some minor releases
in between Betas, mainly to fix any critical bugs. The second beta arrived on June 9th, the third beta on
July 14th, while the fourth beta landed on August 11th.

Alongside supported Google Pixel devices, Android 12 Beta 1 was also made available in the form of a
GSI that can be flashed on a much wider range of devices. OEMs have also joined the party, and you can
flash Beta 1 on the following phones:

ASUS ZenFone 8

iQOO 7 Legend

OnePlus 9

OnePlus 9 Pro

OPPO Find X3 Pro

JBQ@2021
College of Computing Studies

Realme GT

TCL 20 Pro 5G

Xiaomi Mi 11

Xiaomi Mi 11 Ultra

Xiaomi Mi 11 Pro

Xiaomi Mi 11X Pro / Mi 11i / Redmi K40 Pro+

A new built-in remote is also now standard in Android 12, so if you have a TV that runs on Android, or
just a Chromecast, you can use your phone to browse through your favorite shows.

The media player that shows in your Quick Settings has also seen an improvement, where you can allow
certain apps to use this. This can work well if you're switching between Spotify and YouTube, and you
just want to keep using Spotify.

Alongside this, a new feature called Car Key enables you to unlock your compatible smart car with your
phone. This will allow you to unlock, lock and even start the engine from your smartphone.

It uses UWB (ultra-wideband) technology, meaning that you can walk up to your car and it'll unlock,
without you even having to take your phone out.

You'll also be able to share digital access to your vehicle with others – allowing you to lend your car to a
friend without giving them a physical key and allowing them access for a period of time.

Android 12 also promises to make your device faster and more responsive. Google claims that it reduces
the CPU time needed for core system services by up to 22% and reduces the use of big cores by the
system server by up to 15%, all of which should also mean improved battery life.

Downloading and playing games look to be more straightforward in Android 12, where you can start a
new game before the download has even finished. This harkens back to the features that the PlayStation
consoles bring, saving you having to wait for a few hours for a game to finish installing.

Prepared by:

Joel B. Quiambao

Instructor1

JBQ@2021
College of Computing Studies

https://en.wikipedia.org/wiki/Android_(operating_system)

https://www.britannica.com/technology/Android-operating-system

https://www.temok.com/blog/android-version-list/

https://www.techradar.com/news/android-12-news

JBQ@2021
College of Computing Studies

Basic4Android (currently known as B4A) is a rapid application development tool for native
Android applications, developed and marketed by Anywhere Software Ltd.

B4A is an alternative to programming with Java.

B4A includes a visual designer that simplifies the process of building user interfaces that target
phones and tablets with different screen sizes. Compiled programs can be tested in AVD
Manager emulators or on real Android devices using Android Debug Bridge and B4A Bridge.

The language itself is similar to Visual Basic and Visual Basic .Net though it is adapted to the
native Android environment. B4A is an object-based and event-driven language.

 B4A Environment

JBQ@2021
College of Computing Studies

 B4A Designer

 B4A Output

JBQ@2021
College of Computing Studies

Label
A label is a graphical control used to display text.
1. Open B4A and then click File New  Default. Type the project name and click Ok.

JBQ@2021
College of Computing Studies

2. Click Designer  Open Designer. A visual designer will appear with a button already
placed in the designer. Click and delete the button.

JBQ@2021
College of Computing Studies

3. Click Add View  Label. A Label1 will appear on the designer.

4. Click Label1 then go to the Properties and change the Text into “Hello World!”

JBQ@2021
College of Computing Studies

5. Go back to Main Module and press the Run button.

6. Sample Output

JBQ@2021
College of Computing Studies

7. Click Stop button to go back in Main program.

JBQ@2021
College of Computing Studies

Activity #2 – EditText
- A EditText control is used to display, or accept as input, a single line of text.

Click Add View EditText.

JBQ@2021
College of Computing Studies

You can modify the text style and select what input type you will going to use.

JBQ@2021
College of Computing Studies

Button
The Button control represents a standard Windows button. It is generally used to generate a
Click event by providing a handler for the Click event.

You can change the Name, Text, Styles, etc. in the Properties.

JBQ@2021
College of Computing Studies

Button Click Event and Msgbox


An event is a signal that informs an application that something important has occurred. For
example, when a user clicks a control on a form, the form can raise a Click event and call a
procedure that handles the event. Events also allow separate tasks to communicate.

Click Tools then click Generate Members

Expand btnclick(Button) then choose Click event then click Generate Members and then Close.

JBQ@2021
College of Computing Studies

Then go back in Main Module, there you will see that a Sub btnclick Event appeared where
codes will be typed inside this event.

Msgbox

JBQ@2021
College of Computing Studies

Output

Msgbox shows a modal message box with the specified message and title. The dialog will show
one OK button.

MsgboxAsync is recommended to use instead of msgbox because it is a non-modal message box.

Modal dialog boxes must close first before you can execute further actions with the
superordinate window. The file selection dialog box, for example, is a modal dialog box.

Non-modal dialog boxes can remain open while you work with the superordinate window.

JBQ@2021
College of Computing Studies

Prepared by:

Joel B. Quiambao
Instructor1

JBQ@2021
College of Computing Studies

JBQ@2021
College of Computing Studies

Lesson #4 – Conditional Statements (If, If-else, Nested If)


Conditional Statements are used to make decisions based on the
conditions. Conditional statements execute sequentially when there is no
condition around the statements. If you put some condition for a block of
statements, the execution flow may change based on the result evaluated by
the condition. This process is called decision making.

Syntax:

If logical_expression Then
One or more statements
Else
One or more statements
End If

-Revisit the previous Activities and apply the IF Condition needed for that
program.

Sample Activity 1:

JBQ@2021
College of Computing Studies

Code:

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
Private txtname As EditText
Private txt1 As EditText
Private txt2 As EditText
Private txtans As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)


Activity.LoadLayout("Layout")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub btnHello_Click


Msgbox("Hello " & txtname.Text, "Welcome")
End Sub

Private Sub btntimes_Click


If txt1.Text = "" Or txt2.Text = "" Then
Msgbox("Input Value","Warning")
Else
txtans.Text = txt1.Text * txt2.Text
End If

JBQ@2021
College of Computing Studies

End Sub

Private Sub btnplus_Click


If txt1.Text = "" Or txt2.Text = "" Then
Msgbox("Input Value","Warning")
Else
txtans.Text = txt1.Text + txt2.Text
End If
End Sub

Private Sub btnminus_Click


If txt1.Text = "" Or txt2.Text = "" Then
Msgbox("Input Value","Warning")
Else
txtans.Text = txt1.Text - txt2.Text
End If
End Sub

Private Sub btndiv_Click


If txt1.Text = "" Or txt2.Text = "" Then
Msgbox("Input Value","Warning")
Else
txtans.Text = txt1.Text / txt2.Text
End If
End Sub

Private Sub btnclear_Click


txt1.Text=""
txt2.Text=""
txtans.Text=""
txt1.RequestFocus

End Sub

JBQ@2021
College of Computing Studies

Sample Activity 2:

Code:

#Region Project Attributes


#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False

JBQ@2021
College of Computing Studies

#End Region

#Region Activity Attributes


#FullScreen: False
#IncludeTitle: True
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
Private txtprice As EditText
Private txtquan As EditText
Private txttotal As EditText
Private txtcash As EditText
Private txtchange As EditText
Private lblchange As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)


Activity.LoadLayout("Layout")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub btntotal_Click


If txtprice.Text = "" Or txtquan.Text = "" Then
Msgbox("Please input value","Warning")
Else
txttotal.Text = txtprice.Text * txtquan.Text
End If

End Sub

JBQ@2021
College of Computing Studies

Private Sub btnchange_Click


If txtcash.Text="" Or txttotal.Text ="" Then
Msgbox("Please input value","Warning")
Else

If txtcash.Text < txttotal.Text Then


Msgbox("Insufficient Cash","Warning")
Else
txtchange.Text = txtcash.Text - txttotal.Text
End If
End If

End Sub

Private Sub btnclear_Click


txtprice.Text = ""
txtquan.Text = ""
txttotal.Text = "0"
txtcash.Text = ""
txtchange.Text = "0"
txtprice.RequestFocus

End Sub

JBQ@2021
College of Computing Studies

Sample Activity 3:

- Using Nested If
- A nested if statement is an if statement placed inside another if statement. Nested if
statements are often used when you must test a combination of conditions before
deciding on the proper action.

Code:

#Region Project Attributes


#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region

JBQ@2021
College of Computing Studies

#Region Activity Attributes


#FullScreen: False
#IncludeTitle: True
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
Private txtmath As EditText
Private txtsci As EditText
Private txteng As EditText
Private txtfil As EditText
Private txtave As EditText
Private txtrem As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)


Activity.LoadLayout("Layout")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub btnaverage_Click


If txtmath.Text = "" Or txtsci.Text = "" Or txteng.Text = "" Or txtfil.Text = "" Then
Msgbox("Please input grade","Warning")

else If txtmath.Text > 100 Or txtsci.Text > 100 Or txteng.Text > 100 Or txtfil.Text > 100
Then

Msgbox("Invalid grade","Warning")

JBQ@2021
College of Computing Studies

Else

txtave.Text = (txtmath.Text + txtsci.Text + txteng.Text + txtfil.Text) / 4

If txtave.Text < 75 Then


txtrem.Text = "Failed"
Else if txtave.Text <=80 Then
txtrem.Text = "Passed"
else if txtave.Text <=86 Then
txtrem.Text = "Good"
else if txtave.Text <= 90 Then
txtrem.Text = "Very Good"
Else
txtrem.Text = "Excellent"

End If

End If

End Sub

Private Sub btnclear_Click


txtmath.Text = ""
txtsci.Text = ""
txteng.Text = ""
txtfil.Text = ""
txtave.Text = ""
txtrem.Text = ""
txtmath.RequestFocus

End Sub

JBQ@2021
College of Computing Studies

Sample Program:

Code:

#Region Project Attributes


#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region

#Region Activity Attributes


#FullScreen: False
#IncludeTitle: True
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
End Sub

Sub Globals

JBQ@2021
College of Computing Studies

'These global variables will be redeclared each time the activity is created.
Private txtage As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)


Activity.LoadLayout("Layout")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub btnAge_Click


If txtage.Text = "" Then
Msgbox("Please enter age","Warning")
Else if txtage.Text <=2 Then
Msgbox("You are a baby","My Age")
Else if txtage.Text <=7 Then
Msgbox("You are a Kid","My Age")
Else if txtage.Text <=11 Then
Msgbox("You are a Toddler","My Age")
Else if txtage.Text <=19 Then
Msgbox("You are a Teen","My Age")
Else if txtage.Text <=59 Then
Msgbox("You are Old","My Age")
Else
Msgbox("You are a Senior","My Age")
End If

End Sub

Prepared by:

Joel B. Quiambao

Instructor 1

ttps://eecs.oregonstate.edu/ecampus-
video/CS161/template/chapter_4/ifelse.html#:~:text=A%20nested%20if%20statement%20is,deciding%20on%20the%20proper%20action.

JBQ@2021
College of Computing Studies

Lesson #5 – RadioButton
The RadioButton control is used to provide a set of mutually exclusive options. The
user can select one radio button in a group. If you need to place more than one group
of radio buttons in the same form, you should place them in different container controls
like a Panel control.

Syntax:

Sub RadioButton1_CheckedChange(Checked As Boolean)


One or more statements
End Sub

Sample Activity – Using RadioButton

JBQ@2021
College of Computing Studies

Labels

RadioButton

EditText

Things to do
1. Put Label and change the Text into “Pizza”.
2. Put 3 RadioButtons and change their Name into radioham,radiohaw and radioper. Then
their Text will be “Ham and Cheese-200”,”Hawaiian-300”,”Pepperoni-400”.
3. Put another Label and change the Text into “Price”.
4. Add EditText and change the Name into txtprice. Dim txtprice as EditText.
5. Generate all RadioButtons into click event.

JBQ@2021
College of Computing Studies

Generate Members:

Syntax:

JBQ@2021
College of Computing Studies

Output:

JBQ@2021
College of Computing Studies

Using Multiple Sets or Groups of RadioButtons

- To be able to use a multiple sets or groups of RadioButoons, Panel must be placed to hold
the other set of RadioButtons. Revisit the previous program and try to add Panel and inside
the Panel add another set of RadioButtons.

Panel

JBQ@2021
College of Computing Studies

Output:

JBQ@2021
College of Computing Studies

Syntax:

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
Private txtprice As EditText
Private txtprice2 As EditText
Private txttotal As EditText
Private rdoham As RadioButton
Private rdohaw As RadioButton
Private rdopep As RadioButton
Private rdocoffee As RadioButton
Private rdotea As RadioButton
Private rdosoda As RadioButton
End Sub

Sub Activity_Create(FirstTime As Boolean)


Activity.LoadLayout("Layout")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub rdopep_CheckedChange(Checked As Boolean)


txtprice.Text = 400

End Sub

Private Sub rdohaw_CheckedChange(Checked As Boolean)


txtprice.Text = 300
End Sub

JBQ@2021
College of Computing Studies

Private Sub rdoham_CheckedChange(Checked As Boolean)


txtprice.Text = 200
End Sub

Private Sub rdotea_CheckedChange(Checked As Boolean)


txtprice2.Text = 40
End Sub

Private Sub rdosoda_CheckedChange(Checked As Boolean)


txtprice2.Text = 30
End Sub

Private Sub rdocoffee_CheckedChange(Checked As Boolean)


txtprice2.Text = 50
End Sub

Private Sub btntotal_Click


txttotal.Text = txtprice.Text + txtprice2.Text
End Sub

Private Sub btnclear2_Click


txtprice2.Text = 0
rdocoffee.Checked = False
rdotea.Checked = False
rdosoda.Checked = False
End Sub

Private Sub btnclear1_Click


txtprice.Text = 0
rdoham.Checked = False
rdohaw.Checked = False
rdopep.Checked = False

End Sub

JBQ@2021
College of Computing Studies

Sample Activity

Code

#Region Project Attributes


#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region

#Region Activity Attributes


#FullScreen: False
#IncludeTitle: True

JBQ@2021
College of Computing Studies

#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
Private rdo10 As RadioButton
Private rdo20 As RadioButton
Private txttotal As EditText
Private txtprice As EditText
Private txtdiscount As EditText
Private txttotaldis As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)


Activity.LoadLayout("Layout")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub rdo5_CheckedChange(Checked As Boolean)


txtdiscount.Text = "5%"
txttotaldis.Text = txtprice.Text * .05
txttotal.Text = txtprice.Text - txttotaldis.Text

End Sub

Private Sub rdo20_CheckedChange(Checked As Boolean)


txtdiscount.Text = "20%"
txttotaldis.Text = txtprice.Text * .20
txttotal.Text = txtprice.Text - txttotaldis.Text
End Sub

JBQ@2021
College of Computing Studies

Private Sub rdo10_CheckedChange(Checked As Boolean)


txtdiscount.Text = "10%"
txttotaldis.Text = txtprice.Text * .10
txttotal.Text = txtprice.Text - txttotaldis.Text
End Sub

Private Sub rdo0_CheckedChange(Checked As Boolean)

txtdiscount.Text = "0%"
txttotaldis.Text = txtprice.Text * 0
txttotal.Text = txtprice.Text - txttotaldis.Text
End Sub

Output

JBQ@2021
College of Computing Studies

- Revisit the previous Activity (Point of Sale) and add RadioButton on that program.

Code:

#Region Project Attributes


#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region

#Region Activity Attributes


#FullScreen: False
#IncludeTitle: True

JBQ@2021
College of Computing Studies

#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
Private txtprice As EditText
Private txtquan As EditText
Private txttotal As EditText
Private txtcash As EditText
Private txtchange As EditText
Private lblchange As Label
Private txtdisprice As EditText
Private rdo5 As RadioButton
Private rdo10 As RadioButton
Private rdo20 As RadioButton
Private rdo0 As RadioButton
End Sub

Sub Activity_Create(FirstTime As Boolean)


Activity.LoadLayout("Layout")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub btntotal_Click


If txtprice.Text = "" Or txtquan.Text = "" Then
Msgbox("Please input value","Warning")
Else
txttotal.Text = txtprice.Text * txtquan.Text
End If

End Sub

JBQ@2021
College of Computing Studies

Private Sub btnchange_Click


If txtcash.Text="" Or txtdisprice.Text ="" Then
Msgbox("Please input value","Warning")
Else

If txtcash.Text < txtdisprice.Text Then


Msgbox("Insufficient Cash","Warning")
Else
txtchange.Text = txtcash.Text - txtdisprice.Text
End If
End If

End Sub

Private Sub btnclear_Click


txtprice.Text = ""
txtquan.Text = ""
txttotal.Text = 0
txtcash.Text = ""
txtchange.Text = 0
rdo5.Checked = False
rdo10.Checked = False
rdo10.Checked = False
rdo0.Checked = False
txtdisprice.Text = 0
txtprice.RequestFocus
End Sub

Private Sub rdo5_CheckedChange(Checked As Boolean)


txtdisprice.Text = txttotal.Text - (txttotal.Text * .05)
End Sub

Private Sub rdo10_CheckedChange(Checked As Boolean)


txtdisprice.Text = txttotal.Text - (txttotal.Text * .10)
End Sub

Private Sub rdo20_CheckedChange(Checked As Boolean)


txtdisprice.Text = txttotal.Text - (txttotal.Text * .20)
End Sub

Private Sub rdo0_CheckedChange(Checked As Boolean)


txtdisprice.Text = txttotal.Text - (txttotal.Text * 0)
End Sub

JBQ@2021
College of Computing Studies

Prepared by:

Joel B. Quiambao

Instructor 1

JBQ@2021
College of Computing Studies

Lesson #6 – CheckBox
The CheckBox control allows the user to set true/false or yes/no type options. The user
can select or deselect it. When a check box is selected it has the value True, and when
it is cleared, it holds the value False.

Syntax:

Sub CheckBox1_CheckedChange(Checked As Boolean)


If CheckBox1.Checked = True Then
One or more statements
Else
One or more statements
End If
End Sub

Using Checkbox

Labels
CheckBox

EditText

Button

JBQ@2021
College of Computing Studies

Things to do.
1. Put Label and change the Text into “Pizza”.
2. Put 3 CheckBox and change their Name into chkham,chkhaw and chkpep. Then their
Text will be “Ham and Cheese-200”,”Hawaiian-300”,”Pepperoni-400”.
3. Put another Label and change the Text into “Price”.
4. Add EditText and change the Name into txtprice and Text with 0 value. Dim txtprice as
EditText.
5. Add Button and change the Name into btnclear and Text into “Clear”.
6. Generate all CheckBox into CheckedChange event and btnclear into Click event.

Generate Members:

JBQ@2021
College of Computing Studies

Syntax:

JBQ@2021
College of Computing Studies

Output:

JBQ@2021
College of Computing Studies

Activity2 for Checkbox

JBQ@2021
College of Computing Studies

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
Private txtprice As EditText
Private chkham As CheckBox
Private chkhaw As CheckBox
Private chkpep As CheckBox
Private txtprice2 As EditText
Private chkcoffee As CheckBox
Private chktea As CheckBox
Private chksoda As CheckBox
Private txttotal As EditText
Private txtdiscount As EditText
Private txtdisprice As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)


Activity.LoadLayout("Layout")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub chkpep_CheckedChange(Checked As Boolean)


If chkpep.Checked = True Then
txtprice.Text = txtprice.Text + 400

Else
txtprice.Text = txtprice.Text - 400
End If
End Sub

JBQ@2021
College of Computing Studies

Private Sub chkhaw_CheckedChange(Checked As Boolean)


If chkhaw.Checked = True Then
txtprice.Text = txtprice.Text + 300

Else
txtprice.Text = txtprice.Text - 300
End If
End Sub

Private Sub chkham_CheckedChange(Checked As Boolean)


If chkham.Checked = True Then
txtprice.Text = txtprice.Text + 200

Else
txtprice.Text = txtprice.Text - 200
End If
End Sub

Private Sub chktea_CheckedChange(Checked As Boolean)


If chktea.Checked = True Then
txtprice2.Text = txtprice2.Text + 40

Else
txtprice2.Text = txtprice2.Text - 40
End If
End Sub

Private Sub chksoda_CheckedChange(Checked As Boolean)


If chksoda.Checked = True Then
txtprice2.Text = txtprice2.Text + 30

Else
txtprice2.Text = txtprice2.Text - 30
End If
End Sub

Private Sub chkcoffee_CheckedChange(Checked As Boolean)


If chkcoffee.Checked = True Then
txtprice2.Text = txtprice2.Text + 50

Else
txtprice2.Text = txtprice2.Text - 50
End If
End Sub

JBQ@2021
College of Computing Studies

Private Sub btnclear_Click

chkham.Checked = False
chkhaw.Checked = False
chkpep.Checked = False

End Sub

Private Sub btnclear2_Click


chkcoffee.Checked = False
chktea.Checked = False
chksoda.Checked = False
End Sub

Private Sub btntotal_Click


txttotal.Text = txtprice.Text + txtprice2.Text
End Sub

Private Sub rdo20_CheckedChange(Checked As Boolean)


txtdiscount.Text = txttotal.Text * .2
txtdisprice.Text = txttotal.Text - txtdiscount.Text
End Sub

Private Sub rdo10_CheckedChange(Checked As Boolean)


txtdiscount.Text = txttotal.Text * .1
txtdisprice.Text = txttotal.Text - txtdiscount.Text
End Sub

Private Sub rdo0_CheckedChange(Checked As Boolean)


txtdiscount.Text = txttotal.Text * 0
txtdisprice.Text = txttotal.Text - txtdiscount.Text
End Sub

Private Sub rdo5_CheckedChange(Checked As Boolean)


txtdiscount.Text = txttotal.Text * .05
txtdisprice.Text = txttotal.Text - txtdiscount.Text
End Sub

JBQ@2021
College of Computing Studies

Prepared by:

Joel B. Quiambao

Instructor 1

JBQ@2021
College of Computing Studies

Lesson #7 – Multiple Activities

Main Module Pizza Module Drinks Module

Things to do.
1. On Main module click Project →Add New Module →Activity Module. Enter “Pizza” as
module name.
2. Add another activity module and name it as “Drinks”.
3. On Visual Designer, add new layout by clicking File →New and save it as “laypizza”.
4. Add another layout and name it as “laydrinks”.

JBQ@2021
College of Computing Studies

5. Click File on Visual Designer and you will see all the layouts. Click “Layout” and add all
the controls used in designer below and save the layout.

6. Click File and open the laypizza layout. Add all controls used in designer below and save
the layout.

JBQ@2021
College of Computing Studies

7. Click File and open the laydrinks layout. Add all controls used in designer below and
save the layout.

Codes for Main Module

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
Dim priceforpizza As String
Dim pricefordrinks As String

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
Private txtpricepizza As EditText
Private txtpricedrinks As EditText

JBQ@2021
College of Computing Studies

Private txttotal As EditText


End Sub

Sub Activity_Create(FirstTime As Boolean)


Activity.LoadLayout("Layout")
End Sub

Sub Activity_Resume
txtpricepizza.Text = priceforpizza
txtpricedrinks.Text = pricefordrinks
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub btnPizza_Click


StartActivity(Pizza)
End Sub

Private Sub btnDrinks_Click


StartActivity(Drinks)
End Sub

Private Sub btntotal_Click


txttotal.Text = txtpricepizza.Text + txtpricedrinks.Text
End Sub

Codes for Pizza Module

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

JBQ@2021
College of Computing Studies

Private chkham As CheckBox


Private chkhaw As CheckBox
Private chkpep As CheckBox
Private txtprice As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)


'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("laypizza")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub btnHome_Click


Activity.Finish
End Sub

Private Sub btngotodrinks_Click


StartActivity(Drinks)
End Sub

Private Sub btnclear_Click

chkham.Checked = False
chkhaw.Checked = False
chkpep.Checked = False
txtprice.Text = 0
End Sub

Private Sub chkpep_CheckedChange(Checked As Boolean)


If chkpep.Checked = True Then
txtprice.Text = txtprice.Text + 400
Else
txtprice.Text = txtprice.Text - 400
End If
End Sub

JBQ@2021
College of Computing Studies

Private Sub chkhaw_CheckedChange(Checked As Boolean)


If chkhaw.Checked = True Then
txtprice.Text = txtprice.Text + 300
Else
txtprice.Text = txtprice.Text - 300
End If
End Sub

Private Sub chkham_CheckedChange(Checked As Boolean)


If chkham.Checked = True Then
txtprice.Text = txtprice.Text + 200
Else
txtprice.Text = txtprice.Text - 200
End If
End Sub

Private Sub btnAccept_Click


Main.priceforpizza = txtprice.Text
Msgbox("Transaction Confirmed","Successful")
Activity.Finish
End Sub

Codes for Drinks Module

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

Private chkcoffe As CheckBox


Private chktea As CheckBox
Private chksoda As CheckBox
Private txtprice2 As EditText
End Sub

JBQ@2021
College of Computing Studies

Sub Activity_Create(FirstTime As Boolean)


'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("laydrinks")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub btnHome_Click


Activity.Finish
End Sub

Private Sub btnclear_Click


chkcoffe.Checked = False
chktea.Checked = False
chksoda.Checked = False
txtprice2.Text = 0
End Sub

Private Sub chkcoffe_CheckedChange(Checked As Boolean)


If chkcoffe.Checked = True Then
txtprice2.Text = txtprice2.Text + 50
Else
txtprice2.Text = txtprice2.Text - 50
End If
End Sub

Private Sub chktea_CheckedChange(Checked As Boolean)


If chktea.Checked = True Then
txtprice2.Text = txtprice2.Text + 40
Else
txtprice2.Text = txtprice2.Text - 40
End If
End Sub

Private Sub chksoda_CheckedChange(Checked As Boolean)


If chksoda.Checked = True Then
txtprice2.Text = txtprice2.Text + 30

JBQ@2021
College of Computing Studies

Else
txtprice2.Text = txtprice2.Text - 30
End If
End Sub

Private Sub btnaccept2_Click


Main.pricefordrinks = txtprice2.Text
Msgbox("Transaction Confirmed","Successful")
Activity.Finish
End Sub

Prepared by:

Joel B. Quiambao
Instructor 1

JBQ@2021
College of Computing Studies

Lesson #8 – ToastMessageShow and Msgbox2


ToastMessage shows a quick little message that goes out automatically.

Syntax:

ToastMessageShow(Message as CharSequence, LongDuration as Boolean)

Message - the text message to show LongDuration – If true then shows the
message for a long period of time,
otherwise shows the message for a
short period.

JBQ@2021
College of Computing Studies

Msgbox2 shows a modal message box with the specified message and title.

Message - The dialog message.


Title - The dialog title.
Positive - The text to show for the "positive" button. Pass "" to hide the button.
Cancel - The text to show for the "cancel" button. Pass "" to hide the button.
Negative - The text to show for the "negative" button. Pass "" to hide the button.
Icon - A bitmap that will be drawn near the title. Pass Null to hide hide the icon.
Returns one of the DialogResponse values.

Syntax:
Dim result As Int
result = Msgbox2("This is the message", "This is the title", "Good", "", "Bad",
LoadBitmap(File.DirAssets, "smiley.gif"))

If result = DialogResponse.Positive Then ...

JBQ@2021
College of Computing Studies

Things to do.
1. Add Button in any B4A program you made. Name it as btnexit and Text is “Exit”. Generate
Members in Click event.
2. Below is the code for btnexit.

3. You can insert an image or an icon inside msgbox2 by just putting any small size picture
file in Files folder.

4. Just add the below code in the msgbox2.

JBQ@2021
College of Computing Studies

Other use of Msgbox2.


1. Msgbox2 can also be used for computation purposes. You can set Positive, Cancel and
Negative button into an option to be used for computation. See the program below.

JBQ@2021
College of Computing Studies

Syntax:

Prepared by:

Joel B. Quiambao

Instructor 1

JBQ@2021
College of Computing Studies

Lesson #9 – ListView and BackKey


ListView displays a vertically-scrollable collection of views, where each view is
positioned immediately below the previous view in the list.

Sample Output:

ListView

JBQ@2021
College of Computing Studies

Syntax:

- Dim EditText1, EditText2 as EditText , ListView1 as ListView and declare a


variable SelectedItem as Int for the Position of ListView

- Generate Button1(Add) in Click event

JBQ@2021
College of Computing Studies

- Generate Button2(Clear) in Click event

- Generate ListView1 in ItemClick event

- Generate Button3(Delete) in Click event

JBQ@2021
College of Computing Studies

Final Output:

JBQ@2021
College of Computing Studies

BackKey returns you to the previous screen or exits the current menu.

BackKey

JBQ@2021
College of Computing Studies

- Right Click on the Activity Layout, select Generate and click KeyPress (KeyCode
as Int)

Syntax:

JBQ@2021
College of Computing Studies

Prepared by:

Joel B. Quiambao

Instructor 1

JBQ@2021
College of Computing Studies

Lesson #10 – Spinner


Spinner is a folded list that opens when the user clicks on it and allows the user to choose an
item. Similar to WinForms ComboBox.

#Region Project Attributes


#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region

#Region Activity Attributes


#FullScreen: False
#IncludeTitle: True
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.

JBQ@2021
College of Computing Studies

'These variables can be accessed from all modules.


Private xui As XUI
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.

Private Spinner1 As Spinner


Private ListView1 As ListView

End Sub

Sub Activity_Create(FirstTime As Boolean)


Activity.LoadLayout("Layout")

Spinner1.Add("Fruits")
Spinner1.Add("Apple")
Spinner1.Add("Orange")
Spinner1.Add("Grapes")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub Spinner1_ItemClick (Position As Int, Value As Object)


If Spinner1.SelectedIndex = 1 Then
ListView1.AddSingleLine("Apple")
Spinner1.SelectedIndex = 0
Else If Spinner1.SelectedIndex = 2 Then
ListView1.AddSingleLine("Orange")
Spinner1.SelectedIndex = 0
Else If Spinner1.SelectedIndex = 3 Then
ListView1.AddSingleLine("Grapes")
Spinner1.SelectedIndex = 0
End If
End Sub

JBQ@2021
College of Computing Studies

Program #2

#Region Project Attributes


#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region

#Region Activity Attributes


#FullScreen: False
#IncludeTitle: True
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

JBQ@2021
College of Computing Studies

Private xui As XUI


End Sub

Sub Globals
'These global variables will be redeclared each time the
activity is created. Add Dialogs in Libraries (C:\Program
Private Spinner1 As Spinner Files (x86)\Anywhere
Private ListView1 As ListView Software\Basic4android\Libraries)
Private txttotal As EditText
Dim inpdlg As InputDialog
Dim myprice As Double
Dim myitem As String
Dim SelectedItem As Int : SelectedItem = -1
End Sub

Sub Activity_Create(FirstTime As Boolean)


Activity.LoadLayout("Layout")

Spinner1.Add("Fruits") '0
Spinner1.Add("Apple 100") '1
Spinner1.Add("Orange 200") '2
Spinner1.Add("Grapes 300") '3

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub Spinner1_ItemClick (Position As Int, Value As Object)


If Spinner1.SelectedIndex = 1 Then
myitem = "Apple"
myprice = 100
compute

Else If Spinner1.SelectedIndex = 2 Then


myitem = "Orange"
myprice = 200
compute

JBQ@2021
College of Computing Studies

Else If Spinner1.SelectedIndex = 3 Then


myitem = "Grapes"
myprice = 300
compute
End If
End Sub

Sub compute

Dim ans As String


Dim squan As String
Dim subtotal As Double
inpdlg.InputType = inpdlg.INPUT_TYPE_NUMBERS
inpdlg.Input = "1"
ans = inpdlg.Show("Enter Quantity","Quantity","Ok","Cancel","",Null)

If ans = DialogResponse.POSITIVE Then

squan = inpdlg.Input

If squan = "" Then


Msgbox("Plese enter quantity","")
Else
subtotal = myprice * squan
ListView1.AddSingleLine(myitem &" " & myprice &" " &"(" & squan
&")" & " " & subtotal)
txttotal.Text = txttotal.Text + subtotal

Spinner1.SelectedIndex = 0
'inpdlg.Input = ""
End If
End If
End Sub

Private Sub ListView1_ItemLongClick (Position As Int, Value As Object)


Dim ans As String
Dim mydel As String
Dim mysel() As String
Dim mysubtotal As Double

SelectedItem = Position
mydel = ListView1.GetItem(SelectedItem)
mysel = Regex.Split(" ",mydel)
mysubtotal = mysel(3)

JBQ@2021
College of Computing Studies

ans = Msgbox2("Remove this item?",mydel,"Ok","Cancel","",Null)

If ans = DialogResponse.POSITIVE Then


ListView1.RemoveAt(SelectedItem)
txttotal.Text = txttotal.Text - mysubtotal
End If

End Sub

InputDialog - This modal dialog allows the collection of user entered data in the form of text.
The default is free text but the input can be restricted to numeric characters only
or to signed numbers including a decimal point.

Prepared by:

Joel B. Quiambao

Instructor 1

https://www.b4x.com/android/help/dialogs.html#inputdialog

JBQ@2021
College of Computing Studies

Lesson #11 – ImageView


Displays image resources, for example Bitmap or Drawable resources. ImageView is also commonly
used to apply tints to an image and handle image scaling.

Sample Output:

Spinner

ImageView

JBQ@2021
College of Computing Studies

- Download or copy your images and place them under “Files” folder in your
project.

#Region Project Attributes


#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region

#Region Activity Attributes


#FullScreen: False
#IncludeTitle: True
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
Private ImageView1 As ImageView
Private Spinner1 As Spinner
End Sub

Sub Activity_Create(FirstTime As Boolean)


Activity.LoadLayout("Layout")

JBQ@2021
College of Computing Studies

ImageView1.Bitmap = LoadBitmap(File.DirAssets,"hunter.png")

Spinner1.Add("Hunter x Hunter")
Spinner1.Add("Gon")
Spinner1.Add("Killua")
Spinner1.Add("Kurapika")
Spinner1.Add("Leorio")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub Spinner1_ItemClick (Position As Int, Value As Object)


If Spinner1.SelectedIndex = 0 Then
ImageView1.Bitmap = LoadBitmap(File.DirAssets,"hunter.png")
Else If Spinner1.SelectedIndex = 1 Then
ImageView1.Bitmap = LoadBitmap(File.DirAssets,"gon.jpg")
Else If Spinner1.SelectedIndex = 2 Then
ImageView1.Bitmap = LoadBitmap(File.DirAssets,"killua.jpg")
Else If Spinner1.SelectedIndex = 3 Then
ImageView1.Bitmap = LoadBitmap(File.DirAssets,"kurapika.jpg")
Else If Spinner1.SelectedIndex = 4 Then
ImageView1.Bitmap = LoadBitmap(File.DirAssets,"leorio.jpg")
End If
End Sub

JBQ@2021
College of Computing Studies

Program #2 – Choose Image

- Check the Phone in Libraries

JBQ@2021
College of Computing Studies

#Region Project Attributes


#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region

#Region Activity Attributes


#FullScreen: False
#IncludeTitle: True
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
Private txtname As EditText
Private ListView1 As ListView Phone Library
Private ImageView1 As ImageView
Private txtnum As B4XView
Dim MyFile As ContentChooser
Dim SelectedItem As Int : SelectedItem = -1
End Sub

Sub Activity_Create(FirstTime As Boolean)


Activity.LoadLayout("Layout")
ImageView1.Bitmap = LoadBitmap(File.DirAssets,"blank.png")

MyFile.Initialize("MyFile")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

JBQ@2021
College of Computing Studies

End Sub

Private Sub btnadd_Click


ListView1.AddTwoLinesAndBitmap(txtname.Text,txtnum.Text,ImageView1.Bitmap)
txtname.Text=""
txtnum.Text=""

ImageView1.Bitmap = LoadBitmap(File.DirAssets,"blank.png")
End Sub

Private Sub btnimage_Click


MyFile.Show("image/*","Choose Image")
End Sub

Sub MyFile_Result (Success As Boolean, Dir As String, FileName As String)


If Success = True Then
ImageView1.Bitmap = LoadBitmap(Dir, FileName)
Else
ToastMessageShow("Failed",False)
End If
End Sub

Private Sub ListView1_ItemLongClick (Position As Int, Value As Object)


Dim mydel As String
SelectedItem = Position
mydel = ListView1.GetItem(SelectedItem)
Dim ans As String
ans = Msgbox2("Remove this Item?",mydel,"Ok","Cancel","",Null)
If ans = DialogResponse.POSITIVE Then
ListView1.RemoveAt(SelectedItem)
ToastMessageShow("Item removed", False)
End If
End Sub

Prepared by:

Joel B. Quiambao

Instructor 1

JBQ@2021
College of Computing Studies

Lesson #12 – WebView and TabHost


WebView objects allow you to display web content as part of your activity layout, but lack some
of the features of fully-developed browsers. In most cases, we recommend using a standard
web browser, like Chrome, to deliver content to the user.

Sample Output:

WebView

Buttons

JBQ@2021
College of Computing Studies

Syntax:

- Dim WebView1 as WebView

- Generate btngoggle and btnfacebook in Click event

Sample Outputs:

JBQ@2021
College of Computing Studies

TabHost is a container for a tabbed window view. This object holds two children: a set of tab
labels that the user clicks to select a specific tab, and a FrameLayout object that displays the
contents of that page.

- Dim TabHost1 as TabHost

- Create all Layouts to be used in TabHost

JBQ@2021
College of Computing Studies

- Add Tab under Sub Activity_Create

- Sample Output

JBQ@2021
College of Computing Studies

Prepared by:

Joel B. Quiambao

Instructor 1

JBQ@2021

You might also like