Android Adapter Adapter

Source: Internet
Author: User

I. What is an adapter and what is the adapter for?

Adapters are Adapterview views such as ListView-List View control, Gallery-thumbnail browser Control, GridView-Grid control, Spinner-drop-down list control, Autocompletetextview-Auto prompt text box, Expandablelistview-a list control that supports the expand/Shrink feature, and so on) bridges the data to process the data and bind the data to the Adapterview.
Android offers a variety of adapters that can be developed with the most convenient adapters for different data sources, or you can customize the adapter to perform complex functions.

Add:

Adapterview objects have two main tasks
1. Displaying data in layouts
2. Handling User's Choice


The Baseadapter generic adapter base class can be used to bind data to the ListView, Gallery, GridView, spinner, Autocompletetextview, Of course, you can also bind to Expandablelistview.
The Baseexpandablelistadapter extensible adapter base class can be used to bind data to a list control that supports the expand/Shrink feature Expandablelistview, Expandablelistview inherits from the ListView

Two. Related class diagrams and inheritance relationships for two types of adapter base classes

1>baseadapter adapter Related class diagram: Figure 1 and Figure 2

650) this.width=650; "src=" http://pic002.cnblogs.com/images/2012/402670/2012050419375920.jpg "style=" border:0px; " />

Figure 1 Baseadapter adapter related class diagram

650) this.width=650; "src=" http://pic002.cnblogs.com/images/2012/402670/2012050715021849.jpg "style=" border:0px; " />

Figure 2 Baseadapter Adapter related class Diagram (cont.)

2>baseexpandablelistadapter adapter Related class diagram: Figure 3

650) this.width=650; "src=" http://pic002.cnblogs.com/images/2012/402670/2012050715030952.jpg "style=" border:0px; " />

Figure 3 Baseexpandablelistadapter Adapter related class diagram

Three. Specific analysis of related method constructors for important classes

1.ArrayAdapter

650) this.width=650; "src=" http://pic002.cnblogs.com/images/2012/402670/2012050715005471.jpg "style=" border:0px; " />

Add:

Comparison of 1> data sources

1. Assign a value to Arrayadapter with a static character array constant. Advantage, directly with the array write, the data volume is recommended to use.

Static final string[] list= "...";

arrayadapter<string> arrayadapter = new arrayadapter<string> (this,r.layout.list_item,list);

2. Assign a value to the Arrayadapter in the program. Pros: You can write flexibly in your program.

arraylist<string> list = new arraylist<string> ();

List.add ("Data 1");

List.add ("Data n");

arrayadapter<string> arrayadapter = new arrayadapter<string> (this,r.layout.list_item,list);

3. Use an Internationalized interface character array to assign a value to Arrayadapter. Pros: The options for the provided components can be internationalized.

Directory "res" → "values" → "strings.xml" add

<string-array name= "Letter" >
<item>A</item>
<item>B</item>
<item>C</item>
<item>D</item>
</string-array>

arrayadapter<charsequence> adapter = Arrayadapter.createfromresource (this,r.array.letter,android. R.layout.my_list_item)//only need to display

arrayadapter<charsequence> adapter = new Arrayadapter (this,android. R.layout.my_list_item,arrays.aslist (Getresources (). Gettextarray (R.array.letter))//Allow dynamic additions and deletions

2> what happens when using Arrayadapter, when to use Baseadapter

When a large number, such as more than 100 or frequent dynamic increase or decrease when using arrayadapter can easily control the UI,

Use Baseadapter to save resources if only for display


Android Adapter Adapter

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.