Widgets (Views) are the building blocks of every Android screen. You declare them in XML layouts and reference them in Kotlin with findViewById or View Binding.
View vs ViewGroup: A View displays content (TextView, Button). A ViewGroup is a layout that holds other views (LinearLayout, ConstraintLayout).
Widget
Purpose
User Interaction
TextView
Display read-only text
None (can be clickable)
EditText
Text input field
Keyboard typing
Button
Trigger actions
Tap
ImageView
Display images/icons
Tap (optional)
CheckBox
Multiple selections
Toggle on/off
RadioButton
Single selection in a group
Pick one option
Switch
On/off setting
Toggle
Spinner
Dropdown selection
Pick from list
ProgressBar
Loading indicator
None
SeekBar
Slide to pick a value
Drag slider
1TextView
TextView displays static or dynamic text — titles, labels, descriptions, and formatted content.
Kotlin — ProgressBar controlval progressLoading = findViewById<ProgressBar>(R.id.progressLoading)
val progressDownload = findViewById<ProgressBar>(R.id.progressDownload)
// Show indeterminate loader
progressLoading.visibility = View.VISIBLE
// Simulate download progress
lifecycleScope.launch {
for (i in 0..100 step 5) {
progressDownload.progress = i
delay(200)
}
progressLoading.visibility = View.GONE
Toast.makeText(this@MainActivity, "Download complete!", Toast.LENGTH_SHORT).show()
}
Material alternative: For modern apps, consider LinearProgressIndicator or CircularProgressIndicator from Material Components for consistent Material 3 styling.
10SeekBar
SeekBar is a draggable slider for choosing a value in a range — volume, brightness, font size, rating, etc.
XML example
XML — SeekBar with label<TextView
android:id="@+id/tvVolumeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/volume_50" />
<SeekBar
android:id="@+id/seekVolume"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="50"
android:stepSize="1" />
Kotlin — track progress changes
Kotlin — SeekBar listenerval seekBar = findViewById<SeekBar>(R.id.seekVolume)
val tvLabel = findViewById<TextView>(R.id.tvVolumeLabel)
seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
tvLabel.text = "Volume: $progress%"
}
override fun onStartTrackingTouch(seekBar: SeekBar?) {}
override fun onStopTrackingTouch(seekBar: SeekBar?) {
val finalValue = seekBar?.progress ?: 0
saveVolumePreference(finalValue)
}
})
SeekBar vs Slider (Material)
Widget
Package
Notes
SeekBar
android.widget
Classic Android slider, widely used
Slider
Material Components
Material 3 styling, value label, range support
11Hands-On Exercises
1
Build a profile screen with a TextView title, ImageView avatar, and two EditText fields (name, bio). Add a Button that shows a Toast with the entered name.
2
Add email validation to the EditText: show an inline error if the format is invalid using .error = "...".
3
Create a survey with three CheckBox options (hobbies) and a RadioGroup for experience level (Beginner / Intermediate / Advanced). Log selections on submit.
4
Add a Switch for "Receive newsletter" and disable the submit button unless terms CheckBox is checked.
5
Populate a Spinner with 5 cities using ArrayAdapter. Display the selected city in a TextView below.
6
Show an indeterminate ProgressBar for 3 seconds on button click, then hide it. Add a horizontal ProgressBar that fills from 0 to 100.
7
Add a SeekBar (0–100) that updates a "Font Size" label live. Save the value in SharedPreferences when the user releases the slider.
UI Widgets MCQ Practice
10 Basic MCQs10 Advanced MCQs
10 Basic UI Widgets MCQs
1
TextView displays?
ARead-only text
BVideo stream only
CGPS coordinates only
DDex files
Explanation: TextView shows labels and static/copyable text.
2
EditText is for?
AUser text input
BImages only
CBackground services
DAPK signing
Explanation: EditText extends TextView with editable input and IME.
3
Button click listener interface?
AView.OnClickListener
BServiceConnection
CParcelable
DCursor
Explanation: setOnClickListener { } handles tap events.
4
ImageView loads drawable via?
Aandroid:src or setImageResource
BGradle sync
CManifest intent
Dadb install
Explanation: src attribute references @drawable or setImageBitmap in code.
5
CheckBox allows?
AMultiple selections independently
BSingle selection only
CNo user input
DNetwork calls
Explanation: Each CheckBox toggles independently.
6
RadioButton group ensures?
ASingle selection among group
BMultiple mandatory
CNo UI
DAuto GPS
Explanation: RadioGroup enforces one selected RadioButton.
7
Switch toggles?
ABoolean on/off state
BVideo playback only
CSQL transactions
DFragment back stack
Explanation: Switch (CompoundButton) for settings-style toggles.
8
Spinner shows?
ADropdown item selection
BInfinite list virtualized
CMap tiles
DLogcat
Explanation: Spinner uses adapter for dropdown selection (consider Material ExposedDropdownMenu).
9
ProgressBar indicates?
ALoading or indeterminate progress
BFinal score only
CBattery kernel
DLint results
Explanation: Horizontal or circular progress indicators.
10
SeekBar lets user?
ADrag to choose value in range
BType text
CSelect date only
DCompile code
Explanation: SeekBar is draggable progress for volume, brightness, etc.
10 Advanced UI Widgets MCQs
11
TextInputLayout provides?
AMaterial hint/error/helper for EditText
BDatabase layout
CNavigation graph
DHAL bridge
Explanation: TextInputLayout wraps TextInputEditText with floating labels.
12
inputType on EditText?
AControls keyboard and input validation style
BGradle plugin
CAPI 34 only
DIcon density
Explanation: textPassword, number, textEmailAddress, etc.
13
CompoundButton includes?
ACheckBox, RadioButton, Switch
BTextView only
CRecyclerView
DNavHost
Explanation: Shared toggle behavior and checked change listeners.
14
ImageView scaleType centerCrop?
AScales image filling view, may crop
BNever crops
COnly vector
DDisables GPU
Explanation: centerCrop maintains aspect ratio filling bounds.
15
RecyclerView vs Spinner adapter?
ARecyclerView recycles all item types; Spinner uses dropdown adapter
BIdentical
CSpinner faster always
DNeither uses adapter
Explanation: Different UX patterns — Spinner for compact selection.
16
Accessibility contentDescription on ImageView?
AScreen reader spoken label
BEncryption key
CLayout weight
DDex name
Explanation: Essential for TalkBack when image conveys meaning.
17
StateListDrawable?
ADifferent drawable per widget state (pressed, disabled)
BAnimation timeline
CSQL state
DProcess state
Explanation: selector XML in drawable for button states.