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