The Adapter in Android is very useful for customizing the display list, such as SimpleAdapter. Its constructor is:
Public SimpleAdapter (Context context, List> data, int resource, String [] from, int [])
The meanings of its parameters:
1. context, context, SimpleAdapter associated view, which is generally the current Activity, this
2. data: generic List, such as ArrayList, Map, or HashMap
3. resource, resource file, an R. layout, is the layout to be displayed.
4. from, an array, key-value pairs in Map.
5. to, the unique int type identifier formed by the name id in the xml file of layout
For example:
Define a List in a ListActivity:
List> people = new ArrayList> ();
Map m = new HashMap ();
M. put ("name", "tom ");
M. put ("age", "20 ");
People. add (m );
...
SimpleAdapter adapter = new SimpleAdapter (this,
(List>) feets, R. layout. main,
New String [] {"name", "age"}, new int [] {R. id. name, R. id. age });
SetListAdapter (adapter );
Where:
R. id. name, R. id. age are two textviews defined in an XML layout file used to display name and age. The layout file must have a ListView. Or it can be defined in a program.
In addition, you do not need to set setContentView in ListActivity. The system is automatically loaded.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.