Most of the mobile applications interact with the users through the user interface. With Android, several features and tools are available for use so that we can make our application more usable.
Our goal in this section is to:
- Familiarize with the main types of GUI components
- Explore the concepts of:
- Layouts
- Widgets
- Menus
View Hierarchy
Android views are arranged in a hierarchy. All the views in a window are organized in a tree. You show the tree by calling on the method setContentView(rootNode) in the activty.
Layout
- Defines how elements are positioned relative to each other (next to each other, under each other, in a table, grid, etc.)
- Can have a different layouts for each ViewGroup
Widgets
- All are View objects
- Examples:
- TextFields
- EditFields
- Buttons
- Checkboxes
- RadioButtons
- etc.
UI Events
- Usually handled by defining a Listener of the form On<something>Listener and register it with the View
- For example:
- OnClickListener() for handling clicks on Buttons or Lists
- OnTouchListener() for handling touches
- OnKeyListener() for handling key presses
- Alternatively, Override an existing callback if we implemented our own class extending View
Menus
Options Menu
Context Menu
Sub-menu