Android Adapter Simple Introduction to _android

Source: Internet
Author: User
Adapter in Android are useful when customizing display lists, such as Simpleadapter, whose constructors are:
Public Simpleadapter (context context, list> data, int resource, string[] from, int[] to)
The meaning of its various parameters:
1.context, context, simpleadapter Associated view, is generally the current activity,this
2.data, generic list, such as Arraylist,map or HashMap
3.resource, resource file, a r.layout, is the layout to display
4.from, an array, a key-value pair in the map.
A unique int-type identifier formed by a named ID in a 5.to,layout XML file
Like what:
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);
which
R.id.name,r.id.age is the two textview that are defined in an XML layout file to display name and age. There should be a ListView in the layout file. Or it can be defined in the program.
Also, note that you do not need to set the Setcontentview in Listactivity and the system is automatically loaded.
Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.