Android PinnedSectionListView contraction

Source: Internet
Author: User

Android PinnedSectionListView contraction

Open-source projects on the Internet: https://github.com/beworker/pinned-section-listview. this project uses arrayadapter (). It is not suitable for me. You can make some modifications and simulate the interface.

PinnedSectionListView modifies a line of code. Otherwise, an error is reported. The Code is as follows:

Void createPinnedShadow (int position) {}"

 

if (layoutParams == null) {   //layoutParams = (LayoutParams) generateDefaultLayoutParams();layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);    pinnedView.setLayoutParams(layoutParams);}


 

:

 

Code AdapterListView:

 

Package pinneactivity. example. ui; import java. util. arrayList; import pinneactivity. example. ui. pinnedSectionListView. pinnedSectionListAdapter; import android. content. context; import android. view. layoutInflater; import android. view. view; import android. view. viewGroup; import android. widget. baseAdapter; import android. widget. imageView; import android. widget. textView;/*** This is company of adapter ** @ author YangWenlong */public class AdapterListView extends BaseAdapter implements PinnedSectionListAdapter {private ArrayList
 
  
List; private Context context; public ArrayList
  
   
GetList () {return list;} public void setList (ArrayList
   
    
List) {if (list! = Null) {this. list = list;} else {list = new ArrayList
    
     
() ;}} Public AdapterListView (Context context, ArrayList
     
      
List) {this. setList (list); this. context = context;} @ Overridepublic int getCount () {// TODO Auto-generated method stubreturn list. size () ;}@ Overridepublic Bean getItem (int position) {// TODO Auto-generated method stubreturn list. get (position) ;}@ Overridepublic long getItemId (int position) {// TODO Auto-generated method stubreturn position ;}@ Overridepublic View getView (int position, View converView, ViewGroup viewGrop) {// TODO Auto-generated method stubViewHolder VL = null; if (converView = null) {vh = new ViewHolder (); converView = LayoutInflater. from (context ). inflate (R. layout. item, null); Vl. company_item = (TextView) converView. findViewById (R. id. title); Vl. image = (ImageView) converView. findViewById (R. id. imageView1); converView. setTag (VL);} else {HH = (ViewHolder) converView. getTag ();} Bean bean = getItem (position); Vl. company_item.setText (bean. text); if (bean. type = Bean. SECTION) {Vl. company_item.setBackgroundResource (R. drawable. bao_headview_bg); Vl. image. setVisibility (View. GONE);} else {Ku. company_item.setBackgroundResource (R. drawable. details_layout_bg); Vl. image. setVisibility (View. VISIBLE);} return converView;} @ Overridepublic boolean isItemViewTypePinned (int viewType) {// TODO Auto-generated method stubreturn viewType = Bean. SECTION; // 0 is the title and 1 is the content} @ Overridepublic int getViewTypeCount () {return 2; // method in baseAdapter of two view types} @ Overridepublic int getItemViewType (int position) {return (Bean) getItem (position )). type;} public void refresh (ArrayList
      
        Arr) {setList (arr); notifyDataSetChanged ();}}
      
     
    
   
  
 

HeadView:

 

 

Package pinneactivity. example. ui; import android. app. activity; import android. view. view; import android. view. view. onClickListener; import android. widget. linearLayout; import android. widget. toast;/** Fail view ** @ author YangWenlong */public class HeadView implements OnClickListener {private View view = null; private Activity activity; private LinearLayout newFriends; private LinearLayout grop; private LinearLayout tag; private LinearLayout publicNumber; private static HeadView headView = null; public static HeadView getInstance (Activity activity) {headView = new HeadView (activity); return headView ;} public HeadView (Activity activity) {view = activity. getLayoutInflater (). inflate (R. layout. item_head, null); this. activity = activity;} public HeadView initialization () {newFriends = (LinearLayout) view. findViewById (R. id. layout_new); grop = (LinearLayout) view. findViewById (R. id. layout_group); tag = (LinearLayout) view. findViewById (R. id. layout_tag); publicNumber = (LinearLayout) view. findViewById (R. id. layout_public); newFriends. setOnClickListener (this); grop. setOnClickListener (this); tag. setOnClickListener (this); publicNumber. setOnClickListener (this); return headView;} public View getView () {return view;} @ Overridepublic void onClick (View v) {// TODO Auto-generated method stubif (v = newFriends) {Toast. makeText (activity, new friend, Toast. LENGTH_SHORT ). show ();} else if (v = grop) {Toast. makeText (activity, group chat, Toast. LENGTH_SHORT ). show ();} else if (v = tag) {Toast. makeText (activity, Tag, Toast. LENGTH_SHORT ). show ();} else if (v = publicNumber) {Toast. makeText (activity, public number, Toast. LENGTH_SHORT ). show ();}}}

 

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.