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 oneself know, at that time I only look for the development of work, also first experience the girl's disadvantage ...
In the process of looking for work, most of them are internships, with my expectations a little conflict, went to XX group, people as long as 211,985, no way, went to XX factory received a similar address book such a task ...
Talk less, start today's theme
In many applications, it is seen that the group headings are fixed above the Listview:listview slide, and when the second group slips up, the first group follows up, and the next group is fixed until the group slides out of the top edge.
There is a great God written more advanced, you can use to learn from http://blog.csdn.net/guolin_blog/article/details/9033553
Because I compare rookie, so the method is relatively simple, but the realization of the function is similar to the main use of Git source code, directly to call the
1. Download the source code from GitHub, http://blog.csdn.net/guolin_blog/article/details/9033553
2. Import the Pinnedheaderlistview library into the project
3. Create a new project and reference the library
That's about it, here's a quick 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, You can just write it in.
<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 usage is similar, the next step needs to write adapter, personal habits prefer to customize, can follow 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, with the use of the ListView is the same, there is no code.
OK, finish.
Source: http://download.csdn.net/detail/elinavampire/8047885
Android implements fixed head information, squeeze animation (similar to a newsletter)