The use of the "Android" two adapters

Source: Internet
Author: User

Arrayadapter Adapter:
(1) for displaying basic text content
(2) Basic use Process: New Adapter---Create or load data source---Adapter load data source---View load adapter
Arrayadapter (context, the layout file that corresponds to each list item loaded by the current ListView, data Source)
(Arrayadapter) The implementation process of the data adapter:
1. Create a new adapter

Arr_adapter=new arrayadapter<string> (context, layout file, data source)

Arr_adapter=new arrayadapter<string> (Context (this), the current ListView loads each list item corresponding to the layout file (Android. r.layout.simple_list_item_1), Data source (string[]arr_data={"1", "2", "3", "4"});
2. Add a data source to the adapter (included in the previous step)
3. View (ListView) load Adapter
Listview.setadapter (Arr_adapter);

Using Simpleadapter

Private ListView ListView;

Private Simpleadapter Simple_adapter;

Declaring an adapter

Private list<map<string,object>> dataList;
Datalist=new arraylist<map<string,object>> ();
1, create a new data adapter-simpleadapter ();

2. The adapter loads the data source
Simple_adapter = new Simpleadapter (This,getdata () * Gets the data source *,r.layout. layout file name, newstring[]{"key value name 1", "Key Value Name 2"},new int[]{ R.id. Control name 1,r.id. Control Name 2});

3. View (ListView) load Adapter
Listview.setadapter (Simple_adapter);

Generate a data source
Private list<map<string, object>> GetData () {
for (int i=0;i<20;i++) {
Map<string,object> map=new hashmap<string,object> ();
Map.put ("Key value name", R.drawable.ic_launcher);
Map.put ("Key Value name", "Test text" +i);
Datalist.add (map);
}
return dataList;
}

Note: Map.put ("pic", R.drawable.ic_launcher); Map.put ("Text", "Test text" +i); here pic and text with new int[] {R.id.pic,r.id.text} Nothing (just the same name) is associated with the name in new string[] {"pic", "text"}.

The use of the "Android" two adapters

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.