Adapter Adapter binds to a collection data of some type, it determines the child view of AdapterView.
AdapterView The AdapterView object is an implementation of ViewGroup whose child Views are determined by an Adapter that binds to data of some type.
Adapter The Adapter acts like a courier between your data source (perhaps an
array of external strings) and the AdapterView, which displays it.
ListAdapter The bridge between a ListView
and the data that backs the list.
SpinnerAdapter The bridge between a Spinner and its data.
BaseAdapter Common base class of common implementation for an Adapter
that can be used in both ListView and Spinner. If all view in the AdapterView are the same, you can use SimpleAdapter directly; otherwise, you need to extend BaseAdapter.
ArrayAdapter For reading from an arbitrary array (Array or List). A row can only contain one data.
Code Snip a): String[] sw =new String[100]; for (int i =0; i <100; i++) { sw[i] ="listtest_"+ i; } ArrayAdapter<String> adapter =new ArrayAdapter<String(this, android.R.layout.simple_list_item_1, //Use system defined layout file sw); setListAdapter(adapter);
Code Snip b): String[] sw =new String[100]; for (int i =0; i <100; i++) { sw[i] ="listtest_"+ i; }
ArrayAdapter<String> adapter =new ArrayAdapter<String>(this, R.layout.my_simple_list_item, // Use customized layout file R.id.id_textview, //The view (defined in R.layout.my_simple_list_item) to display data sw); setListAdapter(adapter);
Set child view's style of AdapterView: adapter.setDropDownViewResource
xxx
SimpleAdapter An easy adapter to map static data to views defined in an XML file. A row can contains a set of data.
We can back all data into List (such as an ArrayList), the elements of the List is Map (such as HashMap), for example, List<? extends Map<String, ?>> mData. Each entry in the List corresponds to one row in the list (Each row may contain a set of data and each one need to show in the specific sub-view, so we back data of a row into Map that can be get via keys later on). We also specify an XML file that defines the views used to display the row, and a mapping from keys in the Map to specific views (via view id).
Code Snip: (From: http://blog.csdn.net/shichexixi/article/details/5585823) setContentView(R.layout.main); ArrayList<HashMap<String, Object>> users =new ArrayList<HashMap<String, Object>>(); for (int i =0; i <10; i++) { HashMap<String, Object> user =new HashMap<String, Object>(); user.put("img", R.drawable.user); user.put("username", "Name("+ i+")"); user.put("age", (20+ i) +""); users.add(user); } SimpleAdapter saImageItems =new SimpleAdapter(this, users, // Data list R.layout.user, // Define layout of row in AdapterView new String[] { "img", "username", "age" }, // Keys to get data for the correcponding views in current row, the views are specified in the next argument via view id. newint[] { R.id.img, R.id.name, R.id.age } // These id are defined in R.layout.user, the specific data got from Map with keys specified in the previous argument will display in the views . );
// Set Adapter ((ListView) findViewById(R.id.users)).setAdapter(saImageItems);
CursorAdapter & ResourceCursorAdapter & SimpleCursorAdapter For reading database data from a Cursor.
ResourceCursorAdapter Like CursorAdapter, but you can customize layout for row.
SimpleCursorAdapter Like SimpleAdapter, but the difference are:
All data is stored in Cursor rather than List
The data for current row are get via columns name rather than keys
Set child view's style of AdapterView: adapter.setDropDownViewResource
xxx
HeaderViewListAdapter ListAdapter used when a ListView has header and/or footer views.
Refresh AdapterView When you add/remove line(s) to/from Adapter, you can call
Adapter.notifyDataSetChanged() to notify AdapterView to refresh, but if
you only change the contents of existing row, that API doesn't take
effective.
xxx
ExpandableListAdapter An adapter that links a ExpandableListView with the underlying data. The implementation of this interface will provide access to the data of the children (categorized by groups), and also instantiate Views for children and groups.
BaseExpandableListAdapter
CursorTreeAdapter
ResourceCursorTreeAdapter
SimpleCursorTreeAdapter
SimpleExpandableListAdapter
AdapterView AdapterView objects have two main responsibilities:
Filling the layout with data Inserting data into the layout is typically done by binding the AdapterView class to an Adapter, which retrieves data from an external source (perhaps a list that the code supplies or query results from the device's database).
Handling user selections
Classical AdapterView:
ListView / ExpandableListView A view that shows items in a vertically scrolling list.
Methods
getItemAtPosition Is a reference to Adapter.getItem(xxx).
xxx
xxx
Spinner A view that displays one child at a time and lets the user pick among them.