Recently, the company has a new project, inside with a help interface, that is, click on a question, automatically expand the answer below, many people first idea is to write a textview below and set android:visibility= "Gone", when clicked on the code to make it visible ... However, this time, enough to do a lot of things, why not find a better solution? The following code references: http://blog.csdn.net/zoeice/article/details/7729982
The interface to implement the project is as follows:
And our custom Expandablelistview code is:
public class Helpcenterview extends Expandablelistview{private Context mcontext;private list<string> mgroups; Private list<string> mchilds;private helpcenteradapter madapter;public Helpcenterview (context context) {Super ( context); Mcontext = Context;mgroups = Getgroupdata (); mchilds = Getchilddata ();// Hide scroll bar this.setverticalscrollbarenabled (false);//Hide Left default arrow this.setgroupindicator (NULL); Setcachecolorhint ( color.transparent); setdividerheight (0); setchildrendrawnwithcacheenabled (false); Setgroupindicator (null);// Hides the selected yellow highlight colordrawable Drawable_tranparent_ = new colordrawable (color.transparent); Setselector (drawable_tranparent _); Madapter = new Helpcenteradapter (); Setadapter (Madapter);} Public Helpcenterview (context context, AttributeSet Attrs) {This (context);} /** * Get Group Data * @return */private list<string> getgroupdata () {string[] groups = Mcontext.getresources (). Getstrin Garray (R.array.help_center_group); list<string> list = new arraylist<string> (); for (int i=0; i<gRoups.length; i++) {List.add (groups[i]);} return list;} /** * Get Child data * @return */private list<string> getchilddata () {string[] childs = Mcontext.getresources (). Getstrin Garray (R.array.help_center_child); list<string> list = new arraylist<string> (); for (int i=0; i<childs.length; i++) {list.add (childs[i]);} return list;} public class Helpcenteradapter extends Baseexpandablelistadapter {@Overridepublic int getgroupcount () {return Mgroups.size ();} @Overridepublic int getchildrencount (int groupposition) {//child displays only one return 1;} @Overridepublic Object getgroup (int groupposition) {return mgroups.get (groupposition);} @Overridepublic Object getchild (int groupposition, int childposition) {return mchilds.get (groupposition);} @Overridepublic long getgroupid (int groupposition) {return groupposition;} @Overridepublic long Getchildid (int groupposition, int childposition) {return childposition;} @Overridepublic Boolean hasstableids () {return false;} @Overridepublic View getgroupview (int grouPposition, Boolean isexpanded, View Convertview, ViewGroup parent) {if (Convertview = = null) {Convertview = Layoutinflater. From (Mcontext). Inflate (r.layout.item_help_center_group, null);} TextView Grouptext = (TextView) Convertview.findviewbyid (r.id.id_tv_item_help_center_group); ImageView groupimg = ( ImageView) Convertview.findviewbyid (r.id.id_iv_item_help_center_group);//group expand if (isexpanded) { Grouptext.settextcolor (Colorstatelist.valueof (Color.parsecolor ("#ff5e4c")); Groupimg.setimageresource ( R.drawable.icon_more_down);//group when not expanded} else {Grouptext.settextcolor (colorstatelist.valueof ("# 555555 ")); Groupimg.setimageresource (R.drawable.icon_main_more);} Set group content Grouptext.settext (Mgroups.get (groupposition)); return Convertview;} @Overridepublic view Getchildview (int groupposition, int childposition, Boolean islastchild, view Convertview, ViewGroup Parent) {if (Convertview = = null) {Convertview = Layoutinflater.from (Mcontext). Inflate (R.layout.item_help_center_ Child, NULL);} TextView Childtext = (TextView) Convertview.findviewbyid (r.id.id_tv_item_help_center_child); Childtext.settext ( Mchilds.get (groupposition)); return Convertview;} @Overridepublic boolean ischildselectable (int groupposition, int childposition) {return true;}}}
In the layout file, you only need:
<com.example.test.helpcenterview android:id= "@+id/id_elv_help_center" android:layout_width= "Match_ Parent " android:layout_height=" wrap_content " android:dividerheight=" 0.5DP " android:listselector=" # 00000000 " android:divider=" @color/line "/>
Very simple.. The custom Expandablelistview just integrates the adapter inside.
Custom Expandablelistview to implement the app help interface