Android Developer Fundamentals V2 - User Interaction PDF
Document Details

Uploaded by BetterKnownConnemara9267
Tags
Summary
This document is a training material on Android development focusing on user interaction and input controls. It covers concepts such as View focus, click handling, and customization with examples of EditText, CheckBox, and other controls.
Full Transcript
Android Developer Fundamentals V2 User Interaction Chapter 7 This work is licensed under a Android AndroidDeveloper Developer Input Controls Creative Commons Attributi...
Android Developer Fundamentals V2 User Interaction Chapter 7 This work is licensed under a Android AndroidDeveloper Developer Input Controls Creative Commons Attribution 4.0 1 Fundamentals FundamentalsV2V2 International License Input Controls This work is licensed under a Android Developer Input Controls Creative Commons Attribution 4.0 2 Fundamentals V2 International License Contents Overview of input controls View focus Freeform text and numbers Providing choices This work is licensed under a Android Developer Input Controls Creative Commons Attribution 4.0 3 Fundamentals V2 International License Overview of input Controls Android Developer Fundamentals V2 4 Accepting user input Freeform text and numbers: EditText (using keyboard) Providing choices: CheckBox, RadioButton, Spinner Switching on/off: Toggle, Switch Choosing value in range of values: SeekBar This work is licensed under a Android Developer Input Controls Creative Commons Attribution 4.0 5 Fundamentals V2 International License Examples of input controls 1.EditText 2.SeekBar 3.CheckBox 4.RadioButton 5.Switch 6.Spinner This work is licensed under a Android Developer Input Controls Creative Commons Attribution 4.0 6 Fundamentals V2 International License How input controls work 1. Use EditText for entering text using keyboard 2. Use SeekBar for sliding left or right to a setting 3. Combine CheckBox elements for choosing more than one option 4. Combine RadioButton elements into RadioGroup — user makes only one choice 5. Use Switch for tapping on or off 6. Use Spinner for choosing a single item from a list This work is licensed under a Android Developer Input Controls Creative Commons Attribution 4.0 7 Fundamentals V2 International License View is base class for input controls The View class is the basic building block for all UI components, including input controls View is the base class for classes that provide interactive UI components View provides basic interaction through android:onClick This work is licensed under a Android Developer Input Controls Creative Commons Attribution 4.0 8 Fundamentals V2 International License View focus Android Developer Fundamentals V2 9 Focus The View that receives user input has "Focus" Only one View can have focus Focus makes it unambiguous which View gets the input Focus is assigned by ○ User tapping a View ○ App guiding the user from one text input control to the next using the Return, Tab, or arrow keys ○ Calling requestFocus() on any View that is focusable This work is licensed under a Android Developer Input Controls Creative Commons Attribution 4.0 10 Fundamentals V2 International License This work is licensed under a Android Developer Input Controls Creative Commons Attribution 4.0 11 Fundamentals V2 International License Clickable versus focusable Clickable—View can respond to being clicked or tapped Focusable—View can gain focus to accept input Input controls such as keyboards send input to the view that has focus This work is licensed under a Android Developer Input Controls Creative Commons Attribution 4.0 12 Fundamentals V2 International License Which View gets focus next? Topmost view under the touch After user submits input, focus moves to nearest neighbor—priority is left to right, top to bottom Focus can change when user interacts with a directional control This work is licensed under a Android Developer Input Controls Creative Commons Attribution 4.0 13 Fundamentals V2 International License Guiding users Visually indicate which view has focus so users knows where their input goes Visually indicate which views can have focus helps users navigate through flow Predictable and logical—no surprises! This work is licensed under a Android Developer Input Controls Creative Commons Attribution 4.0 14 Fundamentals V2 International License Guiding focus Arrange input controls in a layout from left to right and top to bottom in the order you want focus assigned Place input controls inside a view group in your layout Specify ordering in XML android:id="@+id/top" android:focusable="true" This work is licensed under a android:nextFocusDown="@+id/bottom" Android Developer Fundamentals V2 Input Controls Creative Commons Attribution 4.0 International License 15 Set focus explicitly Use methods of the View class to set focus setFocusable() sets whether a view can have focus requestFocus() gives focus to a specific view setOnFocusChangeListener() sets listener for when view gains or loses focus onFocusChanged() called when focus on a view changes This work is licensed under a Android Developer Input Controls Creative Commons Attribution 4.0 16 Fundamentals V2 International License Find the view with focus Activity.getCurrentFocus() ViewGroup.getFocusedChild() This work is licensed under a Android Developer Input Controls Creative Commons Attribution 4.0 17 Fundamentals V2 International License Freeform text and numbers Android Developer Fundamentals V2 18 EditText for multiple lines of text EditText default Alphanumeric keyboard Suggestions appear Tapping Return (Enter) key starts new line Return key This work is licensed under a Android Developer Input Controls Creative Commons Attribution 4.0 19 Fundamentals V2 International License Customize with inputType XML code for EditText: