Before I learned Pulltorefresh,pinnedheaderexpanablelistview but it was a bit of a hassle to get together. Especially such as QQ. He is not simply the first to be grouped. He's a group. There are several buttons on it, as well as a search box that you can swipe and hover over. I've tried several methods, all of them have bugs. A last-use method.
1. Pulltorefresh with the android.v4 inside, it seems to know is also
2. Hover and group on the web, then I changed the first grouped style to a custom menu menu and emptied the child. This looks like a custom layout and a ListView slide.
3. Here is the style map
The whole part can be slid.
The top will have a color band after the drop-down refresh. A little thin. It's a system effect.
This is the hover effect, and the previous custom menu has been slid up.
Here is the core code, very concise
Packagecom.android.activity;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.os.Handler;ImportAndroid.support.v4.widget.SwipeRefreshLayout;ImportAndroid.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;ImportAndroid.view.View;ImportAndroid.widget.AdapterView;ImportAndroid.widget.ExpandableListAdapter;ImportAndroid.widget.ExpandableListView;ImportAndroid.widget.ExpandableListView.OnChildClickListener;ImportAndroid.widget.ExpandableListView.OnGroupClickListener;ImportAndroid.widget.Toast;ImportCOM.ANDROID.R;ImportCom.android.pinnedheader.PinnedHeaderExpandableListView; Public class mainactivity extends Activity{ PrivatePinnedheaderexpandablelistview Explistview;PrivateSwiperefreshlayout swiperefreshlayout;Privatestring[][] Childrendata =Newstring[Ten][Ten];Privatestring[] Groupdata =Newstring[5];Private intExpandflag =-1;//expansion of Control list PrivateMainadapter adapter;@Override protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.layout_main); Initview (); InitData (); }/** * Initialize view * / Private void Initview() {Explistview = (Pinnedheaderexpandablelistview) Findviewbyid (R.id.explistview); Swiperefreshlayout = (swiperefreshlayout) Findviewbyid (R.id.swipe_container);//Set the color of the animation when refreshing, you can set 4Swiperefreshlayout.setcolorschemeresources (Android. R.color.holo_blue_light, Android. R.color.holo_red_light, Android. R.color.holo_orange_light, Android. R.color.holo_green_light); Swiperefreshlayout.setonrefreshlistener (NewOnrefreshlistener () {@Override Public void Onrefresh() {NewHandler (). postdelayed (NewRunnable () {@Override Public void Run() {swiperefreshlayout.setrefreshing (false); } },6000); } }); }/** * Initialize data * / Private void InitData() { for(intI=0;i<5; i++) {Groupdata[i] ="Group"+i; } for(intI=1;i<5; i++) { for(intj=0;j<Ten; j + +) {Childrendata[i][j] ="QQ"+j; } }//Set hover head viewExplistview.setheaderview (View.inflate (mainactivity. This, R.layout.group,NULL)); adapter =NewMainadapter (Childrendata, Groupdata, Getapplicationcontext (), Explistview); Explistview.setadapter (adapter); Explistview.setonchildclicklistener (NewOnchildclicklistener () {@Override Public Boolean Onchildclick(expandablelistview parent, View V,intGroupposition,intChildposition,LongID) {Toast.maketext (mainactivity. This,"group:"+groupdata[groupposition]+", Buddy:"+childrendata[groupposition][childposition], Toast.length_short). Show ();return false; } }); }}
All you need to do is set up the listener and pass the data, remembering that the first group of data is not displayed, and that the child must be 0.
Menu styles and grouping styles are set here GetView.
Packagecom.android.activity;ImportCOM.ANDROID.R;ImportCom.android.pinnedheader.PinnedHeaderExpandableListView;ImportAndroid.content.Context;Importandroid.opengl.Visibility;ImportAndroid.util.SparseIntArray;ImportAndroid.view.LayoutInflater;ImportAndroid.view.View;ImportAndroid.view.ViewGroup;ImportAndroid.widget.BaseExpandableListAdapter;ImportAndroid.widget.ImageView;ImportAndroid.widget.TextView;ImportAndroid.widget.AbsListView.LayoutParams;ImportAndroid.widget.Toast; Public class mainadapter extendsbaseexpandablelistadapter { PrivateString[][] Childrendata; PublicString[] Groupdata;PrivateContext context;PrivatePinnedheaderexpandablelistview ListView;PrivateLayoutinflater Inflater; Public Mainadapter(string[][] childrendata,string[] groupdata, Context context,pinnedheaderexpandablelistview ListView) { This. Groupdata = Groupdata; This. Childrendata = Childrendata; This. Context = Context; This. ListView = ListView; Inflater = Layoutinflater.from ( This. context); }@Override PublicObjectGetchild(intGroupposition,intChildposition) {returnChildrendata[groupposition][childposition]; }@Override Public Long Getchildid(intGroupposition,intChildposition) {return 0; }@Override PublicViewGetchildview(intGroupposition,intChildposition,BooleanIslastchild, view Convertview, ViewGroup parent) {View view =NULL;if(Convertview! =NULL) {view = Convertview; }Else{view = Inflater.inflate (R.layout.child,NULL); } TextView Text = (TextView) View.findviewbyid (r.id.childto); Text.settext (Childrendata[groupposition][childposition]);returnView }@Override Public int Getchildrencount(intGroupposition) {if(groupposition<0)return 0;returnChildrendata[groupposition].length; }@Override PublicObjectGetgroup(intGroupposition) {returnGroupdata[groupposition]; }@Override Public int GetGroupCount() {returnGroupdata.length; }@Override Public Long Getgroupid(intGroupposition) {return 0; }@Override PublicViewGetgroupview(intGroupposition,Booleanisexpanded, view Convertview, ViewGroup parent) {View view =NULL;//menu if(groupposition==0) {view = Inflater.inflate (R.layout.menu,NULL); View.setlayoutparams (NewLayoutparams (ViewGroup.LayoutParams.MATCH_PARENT, the)); View.settag (1); TextView btn1= (TextView) View.findviewbyid (R.ID.BTN1); Btn1.setonclicklistener (NewView.onclicklistener () {@Override Public void OnClick(View v) {Toast.maketext (context,"Special Care", Toast.length_short). Show (); } });returnView }//General group if(Convertview! =NULL&& (Integer) convertview.gettag () = =0) {view = Convertview; }Else{view = Inflater.inflate (R.layout.group,NULL); View.settag (0); } TextView Text = (TextView) View.findviewbyid (R.id.groupto);if(isexpanded) {Text.settext ("- "+groupdata[groupposition]); }Else{Text.settext ("+ "+groupdata[groupposition]); }returnView }@Override Public Boolean Hasstableids() {return true; }@Override Public Boolean ischildselectable(intGroupposition,intChildposition) {return true; }}
is not very few, need to change their own code on these two files.
Project here: my github address
Stamp Stamp: Https://github.com/younfor/PinnedAndPulledHeaderListView
Android UI design: Imitation QQ friends List group hover, custom header, drop-down refresh combined with demo