UI Components
UI Components
android:layout_margin="16dp" />
android:layout_height="wrap_content"
android:src="@drawable/baseline_android_24"
app:tint="#ff0000" />
Add checkboxes to your app
Checkboxes let the user select one or more
options from a set. Typically, you present
checkbox options in a vertical list.
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Meat" />
<CheckBox android:id="@+id/checkbox_cheese"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cheese"/>
Add radio buttons to your app
Radio buttons let the user select one
option from a set of mutually exclusive
options. Use radio buttons if the user
needs to see all available options listed.
If it's not necessary to show all options,
use a spinner instead.
To create each radio button option, create a <RadioButton
RadioButton in your layout. Because radio android:id="@+id/radio_pirates"
buttons are mutually exclusive, group them inside
a RadioGroup. The system ensures that only one android:layout_width="wrap_content"
radio button within a group can be selected at a
time. android:layout_height="wrap_content"
<?xmlversion="1.0"encoding="utf-8"?> android:text="Pirates"/>
<RadioGroup <RadioButton
android:id="@+id/radio_ninjas"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
android:text="Ninjas"/>
</RadioGroup>
Add toggle buttons
If you're using a View-based layout, there are three main choices for implementing toggles.
We recommend using the SwitchMaterial component from the Material Components library:
Add pickers to your app
Android provides controls for the user to
pick a time or date as ready-to-use
dialogs. These pickers provide controls for
selecting each part of the time (hour,
minute, AM/PM) or date (month, day,
year).
AlertDialog
A dialog that can show a title, up to three buttons, a list of selectable items, or a custom
layout.
DatePickerDialog or TimePickerDialog
A dialog with a predefined UI that lets the user select a date or time.
Add menus
Menus are a common user interface component in
many types of apps. To provide a familiar and
consistent user experience, use the Menu APIs to
present user actions and other options in your
activities.
A context menu is a floating menu that appears when the user performs a touch & hold
on an element. It provides actions that affect the selected content or context frame.
Popup menu
A popup menu displays a vertical list of items that's anchored to the view that invokes
the menu. It's good for providing an overflow of actions that relate to specific content or
to provide options for the second part of a command.
To define a menu, create an XML file inside your project's res/menu/ directory and build the
menu with the following elements:
<menu>
Defines a Menu, which is a container for menu items. A <menu> element must be the root
node for the file, and it can hold one or more <item> and <group> elements.
<item>
Creates a MenuItem, which represents a single item in a menu. This element can contain a
nested <menu> element to create a submenu.
<group>
An optional, invisible container for <item> elements. It lets you categorize menu items so
they share properties, such as active state and visibility. For more information, see the
Create a menu group section.
Key Concepts:
AdapterView: A ViewGroup that displays data, such as ListView, GridView, Spinner, etc.
• Adapter: A bridge between the AdapterView and the data source, responsible for retrieving data and
creating views for each item.
• Data Source: The external source from which the adapter retrieves data, such as an array, database, or
network connection.
2. Retrieve Data: The adapter retrieves data from the specified data source. [4, 6]
3. Create Views: The adapter creates a View for each item in the data source. [4, 7]
4. Display Views: The AdapterView displays the views provided by the adapter. [4]
Common Adapter Types:
• ArrayAdapter: Suitable for simple data sources like arrays and lists. [5, 8]
• CursorAdapter: Used for displaying data from a database cursor. [4]
• BaseAdapter: A base class for creating custom adapters, requiring overriding certain
methods. [4]
• SimpleAdapter: Simplifies the creation of custom adapters by automatically handling
data binding. [4, 6, 9, 10]