4.2.5 Radio Button
java.lang.Object -> android.view.View -> android.widget.TextView -> android.widget.Button -> android.widget.CompoundButton -> android.widget.RadioButton.
A radio button is a two-states button that can be either checked or unchecked. When the radio button is unchecked, the user can press or click it to check it. However, contrary to a CheckBox, a radio button cannot be unchecked by the user once checked.
Radio buttons are normally used together in a RadioGroup. When several radio buttons live inside a radio group, checking one radio button unchecks all the others.
4.2.6 Others
There are other componets like ListView, Gallery, Spinner, ViewFlipper, and the more special-purpose AutoCompleteTextView, ImageSwitcher, QuickContactBadge, date-time pickers, auto-complete input boxes, maps, tab sheets, and TextSwitcher.
I will make examples for those components later. Here, I will just summarize the each component.
ListView A view that shows items in a vertically scrolling list. The items come from the ListAdapter associated with this view.
Gallery A view that shows items in a center-locked, horizontally scrolling list. The default values for the Gallery assume you will be using Theme_galleryItemBackground as the background for each View given to the Gallery from the Adapter. If you are not doing this, you may need to adjust some Gallery properties, such as the spacing. Views given to the Gallery should use Gallery.LayoutParams as their layout parameters type.
Spinner A view that displays one child at a time and lets the user pick among them. The items in the Spinner come from the Adapter associated with this view.
ViewFlipper A View Group that lets us define a collection of Views as a horizontal row in which only one View is visible at a time, and in which transitions between visible views are animated.
AutoCompleteTextView An editable text view that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop down menu from which the user can choose an item to replace the content of the edit box with. The drop down can be dismissed at any time by pressing the back key or, if no item is selected in the drop down, by pressing the enter/dpad center key. The list of suggestions is obtained from a data adapter and appears only after a given number of characters defined by the threshold.
ImageSwitcher
QuickContactBadge Displays a badge showing the image icon assigned to a contact we specify using a phone number, name, e-mail address, or URI. Clicking the image will display the quick contact bar, which provides shortcuts for contacting the selected contact - including calling, sending an SMS, e-mail, and IM.
TextSwitcher Specialized ViewSwitcher that contains only children of type TextView. A TextSwitcher is useful to animate a label on screen. Whenever setText(CharSequence) is called, TextSwitcher animates the current text out and animates the new text in.
4.3 UI Events
Once you've added some Views/widgets to the UI, you probably want to know about the user's interaction with them, so you can perform actions. To be informed of UI events, you need to do one of two things:
Define an event listener and register it with the View. More often than not, this is how you'll listen for events. The View class contains a collection of nested interfaces named OnListener, each with a callback method called On(). For example,
View.OnClickListener for handling "clicks" on a View.
View.OnTouchListener for handling touch screen events in a View.
View.OnKeyListener for handling device key presses within a View. So if you want your View to be notified when it is "clicked" (such as when a button is selected), implement OnClickListener and define its onClick() callback method (where you perform the action upon click), and register it to the View with setOnClickListener().
Override an existing callback method for the View. This is what you should do when you've implemented your own View class and want to listen for specific events that occur within it. Example events you can handle include:
onTouchEvent() Called when the touchscreen is pressed or released, or when it detects movement.
onTrackballEvent() Called when the device's trackball is moved.
onKeyDown() Called when any device key is pressed; includes the D-pad, keyboard, hang-up, call, back, and camera buttons.
onKeyUp() Called when a user releases a pressed key. This allows you to define the default behavior for each event inside your custom View and determine whether the event should be passed on to some other child View. Again, these are callbacks to the View class, so your only chance to define them is when you build a custom component.
4.4 Menus
Menus offer a way to expose application functions without sacrificing valuable screen space. Each Activity can specify its own menu that's displayed when the device's menu button is pressed.
Application menus are another important part of an application's UI. Menus offer a reliable interface that reveals application functions and settings. The most common application menu is revealed by pressing the MENU key on the device. However, you can also add Context Menus, which may be revealed when the user presses and holds down on an item.
Menus are also structured using a View hierarchy, but you don't define this structure yourself. Instead, you define the onCreateOptionsMenu() or onCreateContextMenu() callback methods for your Activity and declare the items that you want to include in your menu. At the appropriate time, Android will automatically create the necessary View hierarchy for the menu and draw each of your menu items in it.
Menus also handle their own events, so there's no need to register event listeners on the items in your menu. When an item in your menu is selected, the onOptionsItemSelected() or onContextItemSelected() method will be called by the framework.
And just like your application layout, you have the option to declare the items for you menu in an XML file.
Full List of Android Tutorials
25. Activity Life Cycle
24. Media
23. HTTP Internet Connection
22. Threads
21. Content Provider
20. Notification and Service
19. Animation - Frame By Frame, Layout, and View
18. Manifest
17. Map View
16. Preferences
15. Configuring Rotation
14. On Notepad Examples
13. Intent
12. Activity Testing
11. Android JUnit Test
10. Menus
9. TabWidget, Flipper, and SlidingDrawer
8. DatePicker, TimePicker, and Clocks
7. Advanced ListView Widget
6. ListView, Spinner
5. Layouts
4. User Interface
3. Back to Hello World Again
2. Hello World
1. Introduction
http://www.bogotobogo.com/android.html
http://www.bogotobogo.com/Android/android25ActivityLifeCycle.html
http://www.bogotobogo.com/Android/android24Media.html
http://www.bogotobogo.com/Android/android23HTTP.html
http://www.bogotobogo.com/Android/android22Threads.html
http://www.bogotobogo.com/Android/android21ContentProvider.html
http://www.bogotobogo.com/Android/android20NotificationService.html
http://www.bogotobogo.com/Android/android19Animation.html
http://www.bogotobogo.com/Android/android18Manifest.html
http://www.bogotobogo.com/Android/android17MapView.html
http://www.bogotobogo.com/Android/android16Preferences.html
http://www.bogotobogo.com/Android/android15Rotation.html
http://www.bogotobogo.com/Android/android13Intent.html
http://www.bogotobogo.com/Android/android12ActivityTesting.html
http://www.bogotobogo.com/Android/android11JUnitTest.html
http://www.bogotobogo.com/Android/android10Menus.html
http://www.bogotobogo.com/Android/android9TabWidgetFlipper.html
http://www.bogotobogo.com/Android/android8DatePickerTimePickerClocks.html
http://www.bogotobogo.com/Android/android7dvancedListView.html
http://www.bogotobogo.com/Android/android6ListViewSpinnerGridViewGallery.html
http://www.bogotobogo.com/Android/android5Layouts.html
http://www.bogotobogo.com/Android/android4UserInterface.html
http://www.bogotobogo.com/Android/android3BackToHelloWorld.html
http://www.bogotobogo.com/Android/android2MyFirstApplication.html
http://www.bogotobogo.com/android.html
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment