Android Guides | Samples

Android.Widget Namespace

The widget package contains (mostly visual) UI elements to use on your Application screen.

Remarks

The widget package contains (mostly visual) UI elements to use on your Application screen. You can also design your own.

To create your own widget, extend View or a subclass. To use your widget in layout XML, there are two additional files for you to create. Here is a list of files you'll need to create to implement a custom widget:

  • Java implementation file - This is the file that implements the behavior of the widget. If you can instantiate the object from layout XML, you will also have to code a constructor that retrieves all the attribute values from the layout XML file.
  • XML definition file - An XML file in res/values/ that defines the XML element used to instantiate your widget, and the attributes that it supports. Other applications will use this element and attributes in their in another in their layout XML.
  • Layout XML [optional]- An optional XML file inside res/layout/ that describes the layout of your widget. You could also do this in code in your Java file.

ApiDemos sample application has an example of creating a custom layout XML tag, LabelView. See the following files that demonstrate implementing and using a custom widget:

  • LabelView.java - The implementation file
  • res/values/attrs.xml - Definition file
  • res/layout/custom_view_1.xml - Layout file

Classes

TypeReason
AbsListViewBase class that can be used to implement virtualized lists of items.
AbsListView+IMultiChoiceModeListenerA MultiChoiceModeListener receives events for AbsListViewChoiceMode.MultipleModal.
AbsListView+IOnScrollListenerInterface definition for a callback to be invoked when the list or grid has been scrolled.
AbsListView+IRecyclerListenerA RecyclerListener is used to receive a notification whenever a View is placed inside the RecycleBin's scrap heap.
AbsListView+ISelectionBoundsAdjusterThe top-level view of a list item can implement this interface to allow itself to modify the bounds of the selection shown for that item.
AbsListView+LayoutParamsAbsListView extends LayoutParams to provide a place to hold the view type.
AbsListView+RecyclerEventArgsProvides data for the AbsListView.Recycler event.
AbsListView+ScrollEventArgsProvides data for the AbsListView.Scroll event.
AbsListView+ScrollStateChangedEventArgsProvides data for the AbsListView.ScrollStateChanged event.
AbsListViewChoiceModeEnumerates values returned by several methods of AbsListViewChoiceMode.
AbsoluteLayoutA layout that lets you specify exact locations (x/y coordinates) of its children.
AbsoluteLayout+LayoutParamsPer-child layout information associated with AbsoluteLayout.
AbsSeekBar [Android Documentation]
AbsSpinnerAn abstract base class for spinner widgets.
ActionMenuViewActionMenuView is a presentation of a series of menu options as a View.
ActionMenuView+IOnMenuItemClickListener
ActionMenuView+LayoutParams
ActionMenuView+MenuItemClickEventArgsProvides data for the ActionMenuView.MenuItemClick event.
AdapterAn Adapter object acts as a bridge between an AdapterView and the underlying data for that view.
AdapterConsts
AdapterViewAn AdapterView is a view whose children are determined by an Adapter.
AdapterView+AdapterContextMenuInfoExtra menu information provided to the IOnCreateContextMenuListener.OnCreateContextMenu(IContextMenu,View,View) callback when a context menu is brought up for this AdapterView.
AdapterView+IOnItemClickListenerInterface definition for a callback to be invoked when an item in this AdapterView has been clicked.
AdapterView+IOnItemLongClickListenerInterface definition for a callback to be invoked when an item in this view has been clicked and held.
AdapterView+IOnItemSelectedListenerInterface definition for a callback to be invoked when an item in this view has been selected.
AdapterView+ItemClickEventArgsProvides data for the AdapterView.ItemClick, AutoCompleteTextView.ItemClick, and ListPopupWindow.ItemClick events.
AdapterView+ItemLongClickEventArgsProvides data for the AdapterView.ItemLongClick event.
AdapterView+ItemSelectedEventArgsProvides data for the AlertDialog+Builder.ItemSelected, AdapterView.ItemSelected, AutoCompleteTextView.ItemSelected, and ListPopupWindow.ItemSelected events.
AdapterView+NothingSelectedEventArgsProvides data for the AlertDialog+Builder.NothingSelected, AdapterView.NothingSelected, AutoCompleteTextView.NothingSelected, and ListPopupWindow.NothingSelected events.
AdapterView<T>An AdapterView is a view whose children are determined by an Adapter.
AdapterViewAnimatorBase class for a AdapterView that will perform animations when switching between its views.
AdapterViewFlipperSimple ViewAnimator that will animate between two or more views that have been added to it.
AlphabetIndexerA helper class for adapters that implement the SectionIndexer interface.
AnalogClockThis widget display an analogic clock with two hands for hours and minutes.
ArrayAdapterA concrete BaseAdapter that is backed by an array of arbitrary objects.
ArrayAdapter<T>A concrete BaseAdapter that is backed by an array of arbitrary objects.
AutoCompleteTextView

java Example

 public class CountriesActivity extends Activity {
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
         setContentView(R.layout.countries);

         ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                 android.R.layout.simple_dropdown_item_1line, COUNTRIES);
         AutoCompleteTextView textView = (AutoCompleteTextView)
                 findViewById(R.id.countries_list);
         textView.setAdapter(adapter);
     }

     private static final String[] COUNTRIES = new String[] {
         "Belgium", "France", "Italy", "Germany", "Spain"
     };
 }
AutoCompleteTextView+IOnDismissListenerListener to respond to the AutoCompleteTextView's completion list being dismissed.
AutoCompleteTextView+IValidatorThis interface is used to make sure that the text entered in this TextView complies to a certain format.
AutoCompleteTextViewIValidatorExtensions
BaseAdapterCommon base class of common implementation for an Adapter that can be used in both ListView (by implementing the specialized IListAdapter interface) and Spinner (by implementing the specialized ISpinnerAdapter interface).
BaseAdapter+InterfaceConsts
BaseAdapter<T>Common base class of common implementation for an Adapter that can be used in both ListView (by implementing the specialized IListAdapter interface) and Spinner (by implementing the specialized ISpinnerAdapter interface).
BaseExpandableListAdapterBase class for a IExpandableListAdapter used to provide data and Views from some data to an expandable list view.
ButtonRepresents a push-button widget.
CalendarViewThis class is a calendar widget for displaying and selecting dates.
CalendarView+DateChangeEventArgsProvides data for the CalendarView.DateChange event.
CalendarView+IOnDateChangeListenerThe callback used to indicate the user changes the date.
CheckBox

java Example

 public class MyActivity extends Activity {
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);

         setContentView(R.layout.content_layout_id);

         final CheckBox checkBox = (CheckBox) findViewById(R.id.checkbox_id);
         if (checkBox.isChecked()) {
             checkBox.setChecked(false);
         }
     }
 }
CheckedTextViewAn extension to TextView that supports the ICheckable interface and displays.
ChoiceModeEnumerates values returned by several types.
ChronometerClass that implements a simple timer.
Chronometer+IOnChronometerTickListenerA callback that notifies when the chronometer has incremented on its own.
CompoundButton
CompoundButton+CheckedChangeEventArgsProvides data for the CompoundButton.CheckedChange event.
CompoundButton+IOnCheckedChangeListenerInterface definition for a callback to be invoked when the checked state of a compound button changed.
CursorAdapterAdapter that exposes data from a ICursor to a ListView widget.
CursorAdapterFlagsEnumerates values returned by the CursorAdapterFlags.AutoRequery, CursorAdapterFlags.None, and CursorAdapterFlags.RegisterContentObserver members and taken as a parameter of the Android.Widget.CursorAdapter..ctor, Android.Widget.ResourceCursorAdapter..ctor, and Android.Widget.SimpleCursorAdapter..ctor members.
CursorTreeAdapterAn adapter that exposes data from a series of ICursors to an ExpandableListView widget.
DatePickerProvides a widget for selecting a date.
DatePicker+DateChangedEventArgs
DatePicker+IOnDateChangedListenerThe callback used to indicate the user changes\d the date.
DialerFilter [Android Documentation]
DialerModeEnumerates values returned by several types.
DigitalClockLike AnalogClock, but digital.
EdgeEffectThis class performs the graphical effect used at the edges of scrollable widgets when the user scrolls beyond the content bounds in 2D space.
EditTextEditText is a thin veneer over TextView that configures itself to be editable.
ExpandableListViewA view that shows items in a vertically scrolling two-level list.
ExpandableListView+ChildClickEventArgsProvides data for the ExpandableListView.ChildClick event.
ExpandableListView+ExpandableListContextMenuInfoExtra menu information specific to an ExpandableListView provided to the IOnCreateContextMenuListener.OnCreateContextMenu(IContextMenu,View,View) callback when a context menu is brought up for this AdapterView.
ExpandableListView+GroupClickEventArgsProvides data for the ExpandableListView.GroupClick event.
ExpandableListView+GroupCollapseEventArgsProvides data for the ExpandableListView.GroupCollapse event.
ExpandableListView+GroupExpandEventArgsProvides data for the ExpandableListView.GroupExpand event.
ExpandableListView+IOnChildClickListenerInterface definition for a callback to be invoked when a child in this expandable list has been clicked.
ExpandableListView+IOnGroupClickListenerInterface definition for a callback to be invoked when a group in this expandable list has been clicked.
ExpandableListView+IOnGroupCollapseListenerUsed for being notified when a group is collapsed
ExpandableListView+IOnGroupExpandListenerUsed for being notified when a group is expanded
Filter
Filter+FilterEventArgs
Filter+FilterResults
Filter+IFilterListener
FrameLayoutFrameLayout is designed to block out an area on the screen to display a single item.
FrameLayout+LayoutParamsPer-child layout information for layouts that support margins.
GalleryA view that shows items in a center-locked, horizontally scrolling list.
Gallery+LayoutParamsGallery extends LayoutParams to provide a place to hold current Transformation information along with previous position/transformation info.
GridAlignEnumerates values returned by several types.
GridLayoutA layout that places its children in a rectangular grid.
GridLayout+AlignmentAlignments specify where a view should be placed within a cell group and what size it should be.
GridLayout+LayoutParamsLayout information associated with each of the children of a GridLayout.
GridLayout+SpecA Spec defines the horizontal or vertical characteristics of a group of cells.
GridOrientationEnumerates values returned by several types.
GridViewA view that shows items in two-dimensional scrolling grid.
HeaderViewListAdapterListAdapter used when a ListView has header views.
HeaderViewListAdapter+InterfaceConsts
HorizontalScrollViewLayout container for a view hierarchy that can be scrolled by the user, allowing it to be larger than the physical display.
IAdapterAn Adapter object acts as a bridge between an AdapterView and the underlying data for that view.
IAdvanceableThis interface can be implemented by any collection-type view which has a notion of progressing through its set of children.
ICheckableDefines an extension for views that make them checkable.
IExpandableListAdapterAn adapter that links a ExpandableListView with the underlying data.
IFilterable
IFilterQueryProviderThis class can be used by external clients of CursorAdapter and CursorTreeAdapter to define how the content of the adapter should be filtered.
IFilterQueryProviderExtensions
IHeterogeneousExpandableListAdditional methods that when implemented make an IExpandableListAdapter take advantage of the Adapter view type mechanism.
IListAdapterExtended Adapter that is the bridge between a ListView and the data that backs the list.
ImageButton

xml Example

 <?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:state_pressed="true"
           android:drawable="@drawable/button_pressed" /> <!-- pressed -->
     <item android:state_focused="true"
           android:drawable="@drawable/button_focused" /> <!-- focused -->
     <item android:drawable="@drawable/button_normal" /> <!-- default -->
 </selector>
ImageSwitcher [Android Documentation]
ImageViewDisplays an arbitrary image, such as an icon.
ImageView+ScaleTypeOptions for scaling the bounds of an image to the bounds of this view.
InputMethodEnumerates values returned by several types.
ISectionIndexerInterface that may implemented on Adapters to enable fast scrolling between sections of an AbsListView.
ISpinnerAdapterExtended Adapter that is the bridge between a Spinner and its data.
ItemEventArgs
ItemViewTypeEnumerates values returned by the ItemViewType.HeaderOrFooter, and ItemViewType.Ignore members.
IWrapperListAdapterList adapter that wraps another list adapter.
LayoutRulesEnumerates values returned by several methods of LayoutRules and taken as a parameter of the RelativeLayout+LayoutParams.AddRule, RelativeLayout+LayoutParams.AddRule, and RelativeLayout+LayoutParams.RemoveRule members.
LinearLayoutA Layout that arranges its children in a single column or a single row.
LinearLayout+LayoutParamsPer-child layout information associated with ViewLinearLayout.
ListPopupWindowA ListPopupWindow anchors itself to a host view and displays a list of choices.
ListPopupWindowInputMethodModeEnumerates values returned by several types.
ListViewA view that shows items in a vertically scrolling list.
ListView+FixedViewInfoA class that represents a fixed view in a list, for example a header at the top or a footer at the bottom.
MediaControllerA view containing controls for a MediaPlayer.
MediaController+IMediaPlayerControl
MultiAutoCompleteTextViewAn editable text view, extending AutoCompleteTextView, that can show completion suggestions for the substring of the text where the user is typing instead of necessarily for the entire thing.
MultiAutoCompleteTextView+CommaTokenizerThis simple Tokenizer can be used for lists where the items are separated by a comma and one or more spaces.
MultiAutoCompleteTextView+ITokenizer
MultiAutoCompleteTextViewITokenizerExtensions
NumberPickerA widget that enables the user to select a number from a predefined range.
NumberPicker+IFormatterInterface used to format current value into a string for presentation.
NumberPicker+IOnScrollListenerInterface to listen for the picker scroll state.
NumberPicker+IOnValueChangeListenerInterface to listen for changes of the current value.
NumberPicker+ScrollEventArgsProvides data for the NumberPicker.Scroll event.
NumberPicker+ValueChangeEventArgsProvides data for the NumberPicker.ValueChanged event.
NumberPickerScrollStateEnumerates values returned by several types and taken as a parameter of the NumberPicker+IOnScrollListener.OnScrollStateChange, and Android.Widget.NumberPicker.ScrollEventArgs..ctor members.
OrientationEnumerates values returned by the LinearLayout.Orientation, Orientation.Horizontal, and Orientation.Vertical members.
OverScrollerThis class encapsulates scrolling with the ability to overshoot the bounds of a scrolling operation.
PackedPositionTypeEnumerates values returned by several types.
PopupMenuA PopupMenu displays a Menu in a modal popup window anchored to a View.
PopupMenu+DismissEventArgsProvides data for the PopupMenu.DismissEvent event.
PopupMenu+IOnDismissListenerCallback interface used to notify the application that the menu has closed.
PopupMenu+IOnMenuItemClickListenerInterface responsible for receiving menu item click events if the items themselves do not have individual item click listeners.
PopupMenu+MenuItemClickEventArgsProvides data for the PopupMenu.MenuItemClick event.
PopupWindow
PopupWindow+IOnDismissListenerListener that is called when this popup window is dismissed.
PositionPromptEnumerates values returned by several types.
ProgressBar
QuickContactBadgeWidget used to show an image with the standard QuickContact badge and on-click behavior.
RadioButton
RadioGroup
RadioGroup+CheckedChangeEventArgsProvides data for the RadioGroup.CheckedChange event.
RadioGroup+IOnCheckedChangeListener
RadioGroup+LayoutParams
RatingBarA RatingBar is an extension of SeekBar and ProgressBar that shows a rating in stars.
RatingBar+IOnRatingBarChangeListenerA callback that notifies clients when the rating has been changed.
RatingBar+RatingBarChangeEventArgsProvides data for the RatingBar.RatingBarChange event.
RelativeLayoutA Layout where the positions of the children can be described in relation to each other or to the parent.
RelativeLayout+LayoutParamsPer-child layout information associated with RelativeLayout.
RemoteViewsA class that describes a view hierarchy that can be displayed in another process.
RemoteViews+ActionExceptionException to send when something goes wrong executing an action
RemoteViews+InterfaceConsts
RemoteViews+RemoteViewThis annotation indicates that a subclass of View is alllowed to be used with the RemoteViews mechanism.
RemoteViewsServiceThe service to be connected to for a remote adapter to request RemoteViews.
RemoteViewsService+IRemoteViewsFactoryAn interface for an adapter between a remote collection view (ListView, GridView, etc) and the underlying data for that view.
ResourceCursorAdapterAn easy adapter that creates views defined in an XML file.
ResourceCursorTreeAdapterA fairly simple ExpandableListAdapter that creates views defined in an XML file.
Scroller

java Example

 private Scroller mScroller = new Scroller(context);
 ...
 public void zoomIn() {
     // Revert any animation currently in progress
     mScroller.forceFinished(true);
     // Start scrolling by providing a starting point and
     // the distance to travel
     mScroller.startScroll(0, 0, 100, 0);
     // Invalidate to request a redraw
     invalidate();
 }

java Example

if (mScroller.computeScrollOffset()) {
     // Get current x and y positions
     int currX = mScroller.getCurrX();
     int currY = mScroller.getCurrY();
    ...
 }
ScrollStateEnumerates values returned by several types and taken as a parameter of the AbsListView+IOnScrollListener.OnScrollStateChanged, and Android.Widget.AbsListView.ScrollStateChangedEventArgs..ctor members.
ScrollViewLayout container for a view hierarchy that can be scrolled by the user, allowing it to be larger than the physical display.
SearchViewA widget that provides a user interface for the user to enter a search query and submit a request to a search provider.
SearchView+CloseEventArgsProvides data for the SearchView.Close event.
SearchView+IOnCloseListener
SearchView+IOnQueryTextListenerCallbacks for changes to the query text.
SearchView+IOnSuggestionListenerCallback interface for selection events on suggestions.
SearchView+QueryTextChangeEventArgsProvides data for the SearchView.QueryTextChange event.
SearchView+QueryTextSubmitEventArgsProvides data for the SearchView.QueryTextSubmit event.
SearchView+SuggestionClickEventArgsProvides data for the SearchView.SuggestionClick event.
SearchView+SuggestionSelectEventArgsProvides data for the SearchView.SuggestionSelect event.
SeekBarA SeekBar is an extension of ProgressBar that adds a draggable thumb.
SeekBar+IOnSeekBarChangeListenerA callback that notifies clients when the progress level has been changed.
SeekBar+ProgressChangedEventArgsProvides data for the SeekBar.ProgressChanged event.
SeekBar+StartTrackingTouchEventArgsProvides data for the SeekBar.StartTrackingTouch event.
SeekBar+StopTrackingTouchEventArgsProvides data for the SeekBar.StopTrackingTouch event.
ShareActionProviderThis is a provider for a share action.
ShareActionProvider+IOnShareTargetSelectedListenerListener for the event of selecting a share target.
ShareActionProvider+ShareTargetSelectedEventArgsProvides data for the ShareActionProvider.ShareTargetSelected event.
ShowDividersEnumerates values returned by several types.
SimpleAdapterAn easy adapter to map static data to views defined in an XML file.
SimpleAdapter+IViewBinderThis class can be used by external clients of SimpleAdapter to bind values to views.
SimpleCursorAdapterAn easy adapter to map columns from a cursor to TextViews or ImageViews defined in an XML file.
SimpleCursorAdapter+ICursorToStringConverterThis class can be used by external clients of SimpleCursorAdapter to define how the Cursor should be converted to a String.
SimpleCursorAdapter+IViewBinderThis class can be used by external clients of SimpleCursorAdapter to bind values fom the Cursor to views.
SimpleCursorAdapterICursorToStringConverterExtensions
SimpleCursorTreeAdapterAn easy adapter to map columns from a cursor to TextViews or ImageViews defined in an XML file.
SimpleCursorTreeAdapter+IViewBinderThis class can be used by external clients of SimpleCursorTreeAdapter to bind values from the Cursor to views.
SimpleExpandableListAdapterAn easy adapter to map static data to group and child views defined in an XML file.
SlidingDrawerSlidingDrawer hides content out of the screen and allows the user to drag a handle to bring the content on screen.
SlidingDrawer+IOnDrawerCloseListenerCallback invoked when the drawer is closed.
SlidingDrawer+IOnDrawerOpenListenerCallback invoked when the drawer is opened.
SlidingDrawer+IOnDrawerScrollListenerCallback invoked when the drawer is scrolled.
SlidingDrawerOrientationEnumerates values returned by several types.
SpaceSpace is a lightweight View subclass that may be used to create gaps between components in general purpose layouts.
SpinnerA view that displays one child at a time and lets the user pick among them.
SpinnerModeEnumerates values returned by the SpinnerMode.Dialog, and SpinnerMode.Dropdown members and taken as a parameter of the Android.Widget.Spinner..ctor, Android.Widget.Spinner..ctor, and Android.Widget.Spinner..ctor members.
StackView [Android Documentation]
StretchModeEnumerates values returned by several types.
SwitchA Switch is a two-state toggle switch widget that can select between two options.
TabHostContainer for a tabbed window view.
TabHost+IOnTabChangeListenerInterface definition for a callback to be invoked when tab changed
TabHost+ITabContentFactoryMakes the content of a tab when it is selected.
TabHost+TabChangeEventArgsProvides data for the TabHost.TabChanged event.
TabHost+TabSpecA tab has a tab indicator, content, and a tag that is used to keep track of it.
TableLayout
TableLayout+LayoutParams
TableRow
TableRow+LayoutParams
TabWidgetDisplays a list of tab labels representing each page in the parent's tab collection.
TextClock
TextSwitcherSpecialized ViewSwitcher that contains only children of type TextView.
TextViewDisplays text to the user and optionally allows them to edit it.
TextView+BufferType
TextView+EditorActionEventArgsProvides data for the TextView.EditorAction event.
TextView+IOnEditorActionListenerInterface definition for a callback to be invoked when an action is performed on the editor.
TextView+SavedStateUser interface state that is stored by TextView for implementing View.OnSaveInstanceState.
TimePickerA widget for selecting the time of day, in either 24-hour or AM/PM mode.
TimePicker+IOnTimeChangedListenerThe callback interface used to indicate the time has been adjusted.
TimePicker+TimeChangedEventArgsProvides data for the TimePicker.TimeChanged event.
ToastA toast is a view containing a quick little message for the user.
ToastLengthEnumerates values returned by the Toast.Duration, ToastLength.Long, and ToastLength.Short members and taken as a parameter of the Toast.MakeText, Toast.MakeText, and Toast.MakeText members.
ToggleButtonDisplays checked/unchecked states as a button with a "light" indicator and by default accompanied with the text "ON" or "OFF".
ToolbarA standard toolbar for use within application content.
Toolbar+IOnMenuItemClickListener
Toolbar+LayoutParams
Toolbar+MenuItemClickEventArgsProvides data for the Toolbar.MenuItemClick event.
TranscriptModeEnumerates values returned by several types.
TwoLineListItem
VideoViewDisplays a video file.
ViewAnimatorBase class for a FrameLayout container that will perform animations when switching between its views.
ViewFlipperSimple ViewAnimator that will animate between two or more views that have been added to it.
ViewSwitcher ViewAnimator that switches between two views, and has a factory from which these views are created.
ViewSwitcher+IViewFactoryCreates views in a ViewSwitcher.
ZoomButton [Android Documentation]
ZoomButtonsControllerThe ZoomButtonsController handles showing and hiding the zoom controls and positioning it relative to an owner view.
ZoomButtonsController+IOnZoomListenerInterface that will be called when the user performs an interaction that triggers some action, for example zooming.
ZoomButtonsController+VisibilityChangedEventArgsProvides data for the ZoomButtonsController.VisibilityChanged event.
ZoomButtonsController+ZoomEventArgsProvides data for the ZoomButtonsController.Zoom event.
ZoomControlsThe ZoomControls class displays a simple set of controls used for zooming and provides callbacks to register for events.