0% found this document useful (0 votes)
11 views17 pages

Lecture 4

The document is a lecture on Mobile Application Development in Java, focusing on UI Views in Android, including RadioButton, RadioGroup, EditText, TextView, and LinearLayout. It explains the functionality and usage of these components, as well as the ListView for displaying data efficiently. Additionally, it discusses the limitations of ListView and suggests RecyclerView for more complex datasets.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views17 pages

Lecture 4

The document is a lecture on Mobile Application Development in Java, focusing on UI Views in Android, including RadioButton, RadioGroup, EditText, TextView, and LinearLayout. It explains the functionality and usage of these components, as well as the ListView for displaying data efficiently. Additionally, it discusses the limitations of ListView and suggests RecyclerView for more complex datasets.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Faculty Of Engineering and Technology

Department of Computer Science


Course: Mobile Application In java

(Lecture-4)

Sayed Mortaza Kazemi


Department of Computer Science
Email: [email protected]
Mobile: +93(0) 795474969
Content

• Introduction to UI Views
Working with
• RadioButton
• RadioGroup
• EditText
• TextView

2
Introduction to UI Views
• UI Views are the building blocks of an Android application's user
interface.
• They are responsible for drawing and event handling.
• Examples: Buttons, TextViews, ImageViews, RadioButtons, etc.
• Android UI components are generally derived from the View class.

3
Key Components of Android UI

• View: Base class for all UI components.


• ViewGroup: A special type of view that can contain other
views (e.g., LinearLayout, RelativeLayout).
• Widgets: Specialized child classes of views (e.g.,
Buttons, TextView).
• Event Handlers: Mechanism for interacting with user
inputs.
4
What is a RadioButton?

• RadioButtons allow users to select one option from a set of


mutually exclusive options.

• They are often used in forms where only one selection is


required.

• Syntax: <RadioButton android:id="@+id/radio_button" />


• Code Example: Display basic XML code for a RadioButton.
5
What is a RadioGroup?
• ARadioGroup is a container for RadioButtons that ensures
only one RadioButton can be selected at a time.
• It's useful for ensuring mutually exclusive options.
• Syntax: <RadioGroup android:id="@+id/radio_group"
/>Code
• Example: Basic XML code for a RadioGroup containing
multiple RadioButtons.

6
What is an EditText?
• EditText is an input widget that allows users to enter and
modify text.
• It’s commonly used in forms, login screens, and comments
sections.
• Syntax: <EditText android:id="@+id/edit_text" />Code
• Example: Basic XML code for an EditText.Image: Example of
an EditText field in a login form.

7
Handling Input with EditText
• Capturing Input from EditText
• You can retrieve user input via getText() method
in Java or Kotlin.
• Example: val userInput = editText.text.toString()
• Code Example: Simple Kotlin code snippet for
retrieving and using EditText input.

8
9
What is a TextView?
• A TextView is a widget used to display static or dynamic text.
• It is often used for labels, instructions, or displaying results.
• Syntax: <TextView android:id="@+id/text_view" />
• Code Example: Basic XML code for a TextView.
• You can change the text of a TextView at runtime using
setText().
• Example: textView.setText("New text value")

10
What is LinearLayout?
• LinearLayout is a ViewGroup that aligns all its child views in a single direction,
either vertically or horizontally.
• It is one of the most basic and commonly used layouts in Android.
• Why Use LinearLayout?
• Simplicity:
• It is easy to implement and is useful for simple UI designs.
• Alignment:
• Ensures a clear, ordered arrangement of views.
• Flexibility:
• Can nest other layouts, allowing complex UIs.
• Weight Distribution:
• Efficient in distributing space among child views using layout weights.

11
Attributes of LinearLayout

android:orientation
Defines the direction of the child views.
 vertical: Aligns child views vertically (stacked on top of each other).
 horizontal: Aligns child views horizontally (side by side).
android:gravity
Aligns the child views inside the LinearLayout (e.g., center, left, right, etc.).
android:layout_weight
Specifies how much space a child view should occupy relative to others.

12
ListView
• is a ViewGroup that displays a vertically scrollable list of items, which can
be populated from an array, database, or other data sources.
• It is one of the most commonly used UI components for displaying large
sets of data efficiently in a mobile app
• Scrolling: Items in a ListView are displayed in a scrollable list format,
which makes it suitable for displaying long lists of items.
• Item Layouts: You can define custom layouts for each item in the list. The
list adapts to the number of items dynamically.
• Recycling Mechanism: ListView uses an internal recycling mechanism to
reuse the views that are out of sight, which helps in optimizing memory
and performance.

13
Basic Usage of ListView
• Step 1: Define the ListView in XML
• Step 2: Prepare the Data
• Step 3: Set Up the Adapter To bind data to the ListView, you need an
adapter (usually an ArrayAdapter or a CustomAdapter for more complex
layouts). An adapter converts the data into views for the ListView
• ArrayAdapter: This is one of the simplest types of adapters that takes data
from a source (e.g., an array or a list) and uses it to populate views in the
ListView.

14
Benefits of ListView
• Step 4: Handling Item Clicks You can handle clicks on individual items
using an OnItemClickListener.
• Efficient Handling of Large Datasets: Thanks to its recycling mechanism,
ListView is efficient in handling large amounts of data without consuming
too much memory.
• Versatility: ListView can be populated from different data sources,
including arrays, lists, and databases.
• Flexibility: You can fully customize the appearance and behavior of the list
items by providing custom layouts and adapters.

15
Limitations of ListView
• Performance: While ListView is efficient, for highly dynamic or complex
datasets.
• RecyclerView (a more advanced component) is often recommended as it
provides more flexibility and better performance.
• RecyclerView is a more modern and flexible replacement for ListView. It
supports more complex layouts, animations, and can handle large
datasets more efficiently.
• If you are working with static lists, ListView is simpler to implement. For
dynamic and performance-intensive lists, you may want to consider using
RecyclerView.

16
Thank You…!

You might also like