Use of the Android adapter adapter

Source: Internet
Author: User

Simpleadapter of the ListView

The Simpleadapter constructor is:

Public Simpleadapter (context context, list<?. extends Map<string,?>> data, int resource, string[] from, int[] To)

The context of the parameter: the contexts, such as this. The view context in which the associated Simpleadapter runs

Parameter Data:map list, list of data to be displayed, this part needs to be implemented by itself, such as the example of GetData (), the type to be consistent with the above, each item to be consistent with the specified entry from

Parameter resource:listview the ID of the individual layout file, this layout is your custom layout, and you want to show what the layout looks like in this layout. This layout must include the control ID defined in to

Parameter from: A list of each item column name that is added to the map, with the column name in the array

parameter to: is an int array, the ID of the array is the ID of the individual controls in the custom layout and needs to correspond to the from above.

The following is a code snippet, although not intended for illustration purposes, but the Simpleadapter usage is complete.

protected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.recall); Sysapplication.getinstance (). Addactivity ( This); ListView= (ListView) This. Findviewbyid (R.id.listview);Listview.setadapter (Getadapter ()); }    protectedSimpleadapter Getadapter () {List<User> users =getusers (); ListNewArraylist();  for(User u:users) {HashMap<string, String> temp =NewHashmap<string, string>(); Temp.put ("Name", U.getusers_name ());            Data.add (temp); } Simpleadapter Adapter=NewSimpleadapter (Getapplicationcontext (), data, R.layout.recall_item,NewString[] {"Name" },                    New int[] {r.id.name}); LOG.I ("Info", "Fill data Complete"); returnadapter; }

The corresponding: (The red font is displayed in the ListView)

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.