0% found this document useful (0 votes)
7 views8 pages

Android UI Components & Event Handling

The document provides a comprehensive breakdown of Android UI components and event handling, organized into exam-ready notes. It includes definitions, XML examples, and sketches for core components like TextView, EditText, Button, ImageView, and RecyclerView, as well as event handling methods such as onClick and onTouch. Additionally, it offers memory aids, mnemonics, and a revision table for quick reference before exams.

Uploaded by

hassanmansuri570
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views8 pages

Android UI Components & Event Handling

The document provides a comprehensive breakdown of Android UI components and event handling, organized into exam-ready notes. It includes definitions, XML examples, and sketches for core components like TextView, EditText, Button, ImageView, and RecyclerView, as well as event handling methods such as onClick and onTouch. Additionally, it offers memory aids, mnemonics, and a revision table for quick reference before exams.

Uploaded by

hassanmansuri570
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Android UI & Events – Easy Notes

Letʼs break down Unit 2 into clear, exam-ready notes, organized for fast learning
and quick revision. Iʼll guide you with definitions, diagrams you can quickly sketch in
the exam, sample answers, tables, and mnemonics.

[Link] UI Components One-line Definitions)


TextView: Shows read-only text (labels/headings). XML <TextView>

EditText: User input field. XML <EditText>

Button: Clickable, triggers actions. XML <Button>

ImageView: Displays image. XML <ImageView>

Layouts: Containers to arrange UI. Examples: LinearLayout,


RelativeLayout, ConstraintLayout
Events: Actions triggered by user (e.g., onClick,
onTouch) Notifications: Short messages Toast,
Snackbar, Dialog) Input validation: Checks
correctness (setError for error)
RecyclerView: Efficient, scrollable list/grid (needs Adapter & ViewHolder)

2. Detailed Notes, Exam-Friendly

a) TextView
Definition: Displays static text
Best Used For: Labels, titles, read-only info
Key XML attributes: android:text, android:textSize, android:textColor

Example:

<TextView
android:id="@+id/tvWelcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to Android!"
android:textSize="18sp" />

Sketch Diagram:
| Welcome to |
Android!

b) EditText
Definition: Input field for user text
Important attributes: android:hint, android:inputType

Example:

<EditText
android:id="@+id/etUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Username"
android:inputType="text" />

Sketch Diagram:

| Enter |
Username

c) Button
Definition: Triggers action when clicked
How to handle click: via android:onClick in XML or setOnClickListener in code
Example:

Sketch Diagram: [ Submit ]

d) ImageView
Definition: Displays images
Important attribute: android:src, android:contentDescription (accessibility)
Diagram: [ App Logo Image ]
e) Layouts Arranging Views)
LinearLayout

Stacks views vertically/horizontally


Key attribute: android:orientation

Exam tip: Use for simple, stacked

RelativeLayout

Positions views relative to parent/other


views Recommended for moderate
complexity

ConstraintLayout

Most flexible, efficient for complex


UIs Uses constraints for positioning
Sketches:

Linear: Stack boxes top-down.


Relative: Boxes with arrows showing "below",
"alignParentEnd" etc. Constraint: Boxes linked with lines
to parent/sides.

f) Event Handling – Responding to User Actions


onClick
Triggered when clicked
Example XML android:onClick="onSubmitClicked"

Example code:
[Link](v -> { /* action */ });

onTouch
For touch/gesture
detection Uses
setOnTouchListener

Returns true if event consumed


g) Notifications in UI
Toast
Short pop-up, fades out
Example: [Link](this, "Data Saved", Toast.LENGTH_SHORT).show();

Snackbar
Pop-up at bottom, can have button (e.g.,
Undo) Dialog
Modal, requires user interaction (e.g., AlertDialog)

h) Input Validation
Why?: Check user input before
processing Example – Empty Check:

if ([Link]().toString().isEmpty()) {
[Link]("Username cannot be empty");
} else {
[Link](this, "Input Accepted", Toast.LENGTH_SHORT).show();
}

i) RecyclerView – Efficient List/Grid


Definition: View for large, scrollable
data Main components:
RecyclerView UI container)
Adapter (binds data)
ViewHolder (holds item views)
Key methods: onCreateViewHolder, onBindViewHolder, getItemCount

Diagram:

| Item 1 |

| Item 2 |

| Item 3 |
3. Sample Short Answers Exam-ready)
Q Define TextView with XML.

TextView is a UI element for showing read-only text.

<TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_

Q Explain onClick event with example.

onClick runs when a view is tapped. Set android:onClick="methodName" and

public void methodName(View v) {


[Link](this, "Clicked", Toast.LENGTH_SHORT).show();
}

implement:

Q What is RecyclerView? Components?

RecyclerView displays scrollable lists efficiently. Components: RecyclerView


(container), Adapter (binds data), ViewHolder (holds views). Steps: Add in
XML, create item layout, implement Adapter, set LayoutManager &
Adapter.

Q Difference between Toast and Snackbar?

Toast is a short, action-less pop-up; Snackbar appears at bottom and can have
an action button (e.g., Undo).

4. How to Draw Diagrams


TextView / EditText / Button / ImageView: Simple boxes with example text inside.
Layouts: Stack boxes for LinearLayout; show directional arrows for
RelativeLayout; use constraint lines for ConstraintLayout.
RecyclerView: Series of item boxes stacked vertically.

5. Memory Aids & Mnemonics


TEBI: TextView, EditText, Button, ImageView.
LRC: Layout types — Linear, Relative,
Constraint. RAV: RecyclerView = Adapter
+ ViewHolder.
Events: Click = Toast; Touch = onTouch.
6. One-page Last-minute Revision Table

Component Purpose XML / Key attribute Quick example / tip

TextView Display text <TextView>, android:text android:text="Welcome"

EditText Input from user <EditText>, android:hint android:hint="Name"

Button Trigger action <Button>, android:onClick android:text="Submit"

ImageView Show image <ImageView>, android:src android:src="logo"

LinearLayout Stack (v/horizontal) android:orientation Simple stacking

RelativeLayout Position relative layout_below Good for small layouts

ConstraintLayout Flexible positioning app:layout_constraint* Best for complex UI

onClick Click handler setOnClickListener Event handling

onTouch Touch detection setOnTouchListener Gestures/MotionEvent

Toast Short popup [Link] Brief info

Snackbar Bottom popup + action [Link] Has action button

Dialog Modal popup AlertDialog Confirm/cancel

RecyclerView Efficient list display <RecyclerView>, Adapter Adapter + ViewHolder

[Link] 4 5 Mark Questions Formula for Answers)


Definition 1 2 lines)
2 3 key attributes/uses
Short example/code
Sketched diagram (if relevant)

What to Do Next:
If you want to practice with MCQs or flashcards, let me know. Would you like
diagrams you can print or annotate, or do you need to clarify any specific part?
Letʼs make sure youʼre confident for your exam!

You might also like