Expandablelistview basic knowledge 1. General overview of ExpandablelistviewExpandablelistview is a control that can implement the dropdown list in Android , is a vertical scrolling mind two levels list Items Accordion try, the list item is from Expandablelistviewaadapter, and the group can be expanded separately. ?2. Important Methods:expandgroup (int grouppos);// Expand a group in the grouped list view, setselectedgroup (int groupposition);// Set Select the specified group. setselectedchild (int groupposition, int childposition, Boolean shouldexpandgroup); Getpackedpositiongroup (long packedposition);// returns the selected group isgroupexpanded (int groupposition);// Determine if this group is expanded Expandablelistview.setdivider (); this is to set the split line between each Group. Expandablelistview.setgroupindicator (); This is the icon that is set before each Group . expandablelistview.collapsegroup (int group); to close the group 3. introduction of the adapter Expandablelistadapter, an interface that links the underlying data to a Expandablelistview. This connection The implementation of the port will provide access to the child's data ( categorized by group ), and instantiate the child and group. The common weight in the Adapterto approach:getchildid (int groupposition, int childposition) Gets the data associated with giving the child in a given group. getchildrencount (int groupposition) returns the number of child in the specified Group 4. Properties and Events 1) Click events for sub-entries in Android are implemented via Onchildclick () 2) The Click event of the group is implemented by Ongroupclick() Gson frame : It is a framework for Google to launch a request for network data, commonly used as follows:1) Two important methods of Gsonin the gson API , two important methods are available: theToJson () and the Fromjson () methods. Where theToJson () method used to convert a Java object to the appropriate JSON data, theFromjson () method is used to implement the conversion of JSON data to the corresponding Java object. 2) The ToJson () method, theToJson () method, is used to convert a Java object to the appropriate JSON data, mainly in the following forms: String ToJson (jsonelement jsonelement); String ToJson (Object src); String ToJson (Object src, Type typeofsrc); where the method (1.1) is used to convert Jsonelement objects (which can be jsonobject,Jsonarray, and so on) to JSON The method (1.2) is used to serialize the specified object object into the corresponding JSON data; method (3) is used to assign the specified Object Objects (which can include generic types) to be serialized into the corresponding JSON data. 3) 1.2 Fromjson () method The Fromjson () method is used to convert JSON data to the appropriate Java object, mainly in the following ways: (1)<T> T Fromjson (jsonelement json, class<t> Classoft); (2)<T> T Fromjson (jsonelement json, Type Typeoft); (3)<T> T Fromjson (Jsonreader Reader, Type Typeoft); (5)<T> T Fromjson (Reader Reader, Type Typeoft); (6)<T> T Fromjson (String json, class<t> Classoft); (7)<T> T Fromjson (String json, Type Typeoft); The methods above are used to parse different forms of JSON data into Java objects. so Gson is a good framework for requesting network data, which can generate a JSON string on the server side , and then The client parses the data by sending a request to the server side. 5. Picasso Framework This is also the framework of a third party involved in this course, which is mainly used for Web request pictures when a framework, itsThe small amount of code, with its own cache, is a framework worth using. First of all, Picasso is also a afinal of this framework, afinal is an android IOC,ORM framework that has built-in four module functions: finalacitivity,finalbitmap,finaldb,finalhttp. Through The finalactivity, we can annotate the way into Row binding UI and events. With Finalbitmap, we can easily load bitmap pictures without considering oom etc. problem. Through the finaldb module, our line of code can be added to the android SQLite database for pruning and checking. Through finalhttp module, we can request HTTP data in the form of Ajax .
Expandablelistview and expandablelistactivity
How to get Expandablelistview objects
1. You can add Expandablelistview directly to the XML layout in activity through the ID bound control
2.activity inheritance expandablelistactivity obtained by Getexpandablelistview method
Common Properties of Expandablelistview
android:groupindicator= "" Setting expandable Group icon hint
Click events
//set up Group click events//Melv.setongroupclicklistener (NewExpandablelistview.ongroupclicklistener () {@Override PublicBoolean Ongroupclick (Expandablelistview expandablelistview, view view,intILongl) {return false; } }); //Set Word entry Click eventsMelv.setonchildclicklistener (NewExpandablelistview.onchildclicklistener () {@Override PublicBoolean Onchildclick (Expandablelistview expandablelistview, view view,intIintI1,Longl) {return false; } });
Enter the demo link below
1. Achieve accordion effect get local data
Android Accordion Effect implementation