Half a year ago, when I was a senior student, every day looking for work through, want to go to Beijing to experience the Ant clan life, Huff left Jinan, hey ... In Jinan our school or named sizable good school, went to Beijing is nothing, all the bitterness only have their own know, at that time I only find the development of work, but also the first experience of the girl's disadvantage ...
In the process of looking for a job, most of them are internships, with my expectations a little conflict, went to XX group, people just want 211,985, no way, went to XX factory received a similar address book such a task ...
Talk less, start today's theme
In very many applications, it is seen that the group headings are fixed on top of this listview:listview sliding process. When the second group slips up, the first group follows the slide, and the next group is fixed until the group also slides out of the top edge.
One of the great gods wrote more advanced, and could learn from http://blog.csdn.net/guolin_blog/article/details/9033553.
Because I am more novice, so the method is relatively simple, but the implementation of the function is almost the same, mainly using the Git source code, directly to call the
1. Download the source code from GitHub, Https://github.com/JimiSmith/PinnedHeaderListView
2. Import the Pinnedheaderlistview library into the project
3. Create a new project and reference the library
That's about it, here's a brief introduction to the code:
1. Add the following code to the mainactivity layout file:
Give a little tip, hold shift+ctrl+t, enter Pinnedheaderlistview to find Za.co.immedia.pinnedheaderlistview.PinnedHeaderListView, Just write it in to
<za.co.immedia.pinnedheaderlistview.pinnedheaderlistview android:id= "@android: Id/list" android: Layout_width= "Match_parent" android:layout_height= "Match_parent"/>
2. In fact, Pinnedheaderlistview inherited the ListView, so the use of methods are almost the same, the next step will need to write adapter, personal habits more like their own definition, can according to their own ideas to write, But adapter to inherit Sectionedbaseadapter
/** * */package com.thea.pinnedsectiondemo.adapter;import java.util.list;import Com.thea.pinnedsectiondemo.r;import Android.content.context;import Android.view.view;import Android.view.viewgroup;import Android.widget.LinearLayout ; Import Android.widget.textview;import za.co.immedia.pinnedheaderlistview.sectionedbaseadapter;/** * @author Thea * * 2014-10-16 */public class Mypinnedlistviewadapter extends Sectionedbaseadapter{private list<string> sectionList ;p rivate list<string> list;private Context context;public mypinnedlistviewadapter (context context,list< String> sectionlist, list<string> List) {super (); this.sectionlist = Sectionlist;this.list = List;this.context = Context;} @Overridepublic Object getItem (int section, int position) {//TODO auto-generated method Stubreturn null;} @Overridepublic long Getitemid (int section, int position) {//TODO auto-generated method Stubreturn 0;} @Overridepublic int Getsectioncount () {//TODO auto-generated method Stubreturn SectIonlist.size ();} @Overridepublic int getcountforsection (int section) {//TODO auto-generated method Stubreturn list.size ();} @Overridepublic View Getitemview (int section, int position, View convertview,viewgroup parent) {Viewhold hold=null;if (CO Nvertview==null) {hold=new viewhold (); Convertview=linearlayout.inflate (context, r.layout.list_item, null); hold.tv_ Item= (TextView) Convertview.findviewbyid (R.id.tv_item); Convertview.settag (hold);} else {hold= (viewhold) Convertview.gettag ();} Hold.tv_item.setText (List.get (position)); return Convertview;} @Overridepublic View Getsectionheaderview (int section, view Convertview,viewgroup parent) {Viewhold hold=null;if ( Convertview==null) {hold=new viewhold (); Convertview=linearlayout.inflate (context, r.layout.section_item, null); hold.tv_section= (TextView) Convertview.findviewbyid (R.id.tv_section_item); Convertview.settag (hold);} else {hold= (viewhold) Convertview.gettag ();} Hold.tv_section.setText (Sectionlist.get (section)); return Convertview;} Class viewhold{Private TextView Tv_section,tv_item;}}
3. The rest is mainactivity, in fact, the use of the ListView is the same, there is no code.
OK, finished.
Source code: http://download.csdn.net/detail/elinavampire/8047885
Android implements fixed head information, squeeze Animation (similar newsletter)