Download presentation
Presentation is loading. Please wait.
Published byScott Dean Modified over 6 years ago
1
Android Development: Advanced Widgets using Adapters
Richard S. Stansbury 2015
2
Adapters ListView Spinner GridView ExpandableListView Gallery
These all extend AdapterView
3
Adapters Adapters store content that are then displayed by the AdapterView classes e.g. ArrayAdapter CursorAdapter ListAdapter SpinnerAdapter
4
ArrayAdapter ArrayAdapter (Context context, int resource, T [] objects) context – context from which you are building the ArrayAdapter resource – R.id.<identifier> specifies the view that is used to encapsulate the data objects – objects to be displayed toString() is performed on each item in the object array and the appropriate TextView derivative is generated Example: ArrayAdapter a = new ArrayAdapter(this, android.R.Layout.simple_list_item_1, items);
5
ListView Displays a list of strings
List items can be selected or clicked extending ListActivity is an easy approach, but requires a different type of ID XML <ListView android:id = “android:id/list” android:layout_width = “fill_parent” android:layout_height = “wrap_content” >
6
ListView (continued) Java setAdapter(…) setOnItemSelectedListener(…)
Sets the adapter to display setOnItemSelectedListener(…) Sets the listener for when an item is selected setOnItemClickListener(…) Sets the listener for an item being clicked setOnScrollListener(…) Records scroll event getSelectedItem() Returns the object for the currently selected item.
7
Example How do we specify a list?
Ignore the multiple lines per item…this was a default of the layout viewer
8
ListView: Selection Modes
As an alternative to tracking clicks Single selection or multiple selection Java: setChoiceMode(mode) mode = {CHOICE_MODE_SINGLE, CHOICE_MODE_MULTIPLE} XML: android:choiceMode = “multipleChoice” Resource ID: android.R.layout.simple_list_item_single_choice android.R.simple_list_item_multiple_chioce
9
Example
10
Spinner A fancy term for a drop down menu
i.e. a List View that is initially collapsed and when clicked expands providing a scrollable view of the list <spinner android:layout_width = “fill_parent” android:layout_height = “fill_parent” />
11
Spinner (continued) Java setAdapter setOnItemSelectedListener
setDropDownViewResource - used to configure the adapter (not spinner)
12
Example
13
Example
14
Challenge Build / Demo Note: cropped from full portrait view to fit on slides.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.