Innovation stems from imitation 4: enhanced expandablelistview

Source: Internet
Author: User

Continue to discuss how to implement the enhanced version of expandablelistview in Mobile QQ, for example:

 

 

The default expandablelistview group header of Android cannot be fixed on the interface. When scrolling down, it cannot indicate the group to which the currently displayed child belongs, tableview in the iPhone is very good.

 

Therefore, we will create a prompt box fixed at the top of the list to display the group information of the expanded child objects currently displayed.

 

Ideas:
1. First, place a textview as the indicator on the listview, which is aligned with the list.
2. process the upstream/downstream callback of the list:
If (the first row is group) {<br/> If (the second row is also group) Hidden indicator; <br/> else if (the second row is the first child in the first row) display indicator; <br/>}< br/> else {<br/> If (when the second row is group and the first row is incomplete) hides the indicator; <br/>}< br/>

 

 

That's it, right?

 

 

Public class groupheaderindicator extends textview <br/> implements onscrolllistener {</P> <p> @ override <br/> Public void onscroll (abslistview view, int firstvisibleitem, <br/> int visibleitemcount, int totalitemcount) {<br/> // todo auto-generated method stub </P> <p> expandablelistview listview = (expandablelistview) view; <br/> // the ID of the group to which the first row belongs <br/> int gid = expandablelistview. getpackedpositiongroup (Listview. getexpandablelistposition (firstvisibleitem); <br/> // The subid of the current first line <br/> int cid = expandablelistview. getpackedpositionchild (listview. getexpandablelistposition (firstvisibleitem); <br/> // The subid of the second row <br/> int nid = expandablelistview. getpackedpositionchild (listview. getexpandablelistposition (firstvisibleitem + 1); </P> <p> buddieslistadapter adapter = (buddieslistadapter) listview. getexpandablelist Adapter (); </P> <p> string gtitle = (GID>-1 )? Adapter. getgroup (GID ). tostring (): ""; </P> <p> // if both the first and second rows are group headers, no need to display <br/> If (cid =-1 & nid =-1) {<br/> This. setvisibility (view. gone); <br/>}< br/> else {<br/> // It is actually a child, and the next row is group <br/> If (nid =-1 & cid> = 0) {<br/> This. setvisibility (view. gone); <br/> return; <br/>}< br/> This. setvisibility (view. visible); <br/> This. settext (gtitle); <br/> This. postinvalidate (); <br/>}</P> <p>

 

Everything is so simple, and then let's see where it is:

 

<Framelayout <br/> xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" </P> <p> Android: padding = "8.0dip" <br/> Android: layout_weight = "1.0"> <br/> <expandablelistview <br/> Android: Id = "@ ID/buddies_list" <br/> Android: scrollbars = "vertical" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> Android: layout_marginleft = "0.0dip" <br/> Android: drawselectid Top = "false" <br/> Android: scrollingcache = "true" <br/> Android: layout_weight = "1.0" <br/> Android: fastscrollenabled = "false" <br/> Android: footerdividersenabled = "true" <br/> Android: cachecolorhint = "#00000000" <br/> Android: groupindicator = "@ drawable/expander_group" <br/> style = "@ style/widget. listviewgreen "mce_style =" @ style/widget. listviewgreen "<br/> </P> <p> <CN. sharetop. demo. UI. groupheaderindicator <br/> Android: Id = "@ ID/buddies_group_indicator" <br/> Android: textcolor = "#333333" <br/> Android: gravity = "Left | Center" <br/> Android: paddingleft = "32.0dip" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "44.0dip" <br/> Android: background = "@ drawable/expand_group_bar" <br/> </P> <p> </framelayout> </P> <p>

 

In order to save trouble, I directly sent this indicator from textview. In fact, you can make more effects from a viewgroup or something.

 

Careful friends can find out that in QQ, when the list is moved, one effect is that the next group header will display the indicator to the screen, which saves time. I didn't do this, extend it to your brother.

 

In addition, the decompiled QQ code shows that its implementation is actually a class called iphonetreeview, inheriting expandablelistview, which is more flexible and better. Similarly, if you want to achieve more perfect results, there are still many things to do.

 

Recently I want to learn about the development of the iPhone. I have no motivation to continue writing this question. So, I just want to give you some suggestions here. If you have made better results, please share them.

 

Thank you!

 

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.