Android Open Source - AndroidSectionHeaders Sample Section Adapter






From Project

Back to project page AndroidSectionHeaders.

License

The source code is released under:

Apache License

If you think the Android project AndroidSectionHeaders listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.marczych.androidsectionheaders.sample;
/*from  w ww.  j av a  2 s.c om*/
import java.util.ArrayList;

import android.content.Context;

import android.view.View;
import android.view.ViewGroup;

import com.marczych.androidsectionheaders.Section;

import android.widget.AdapterView;
import android.widget.TextView;
import android.widget.Toast;

public class SampleSectionAdapter extends Section {
   private Context mContext;
   private ArrayList<String> mList;
   private String mHeader;

   public SampleSectionAdapter(Context context, ArrayList<String> list,
    String header) {
      mContext = context;
      mList = list;
      mHeader = header;
   }

   public int getCount() {
      return mList.size();
   }

   public Object getItem(int position) {
      return mList.get(position);
   }

   public long getItemId(int position) {
      return position;
   }

   public View getView(int position, View convertView, ViewGroup parent) {
      TextView view = (TextView)convertView;

      if (view == null) {
         view = new TextView(mContext);
         view.setTextSize(30);
      }

      view.setText(mList.get(position));

      return view;
   }

   @Override
   public Object getHeaderItem() {
      return mHeader;
   }

   @Override
   public View getHeaderView(View convertView, ViewGroup parent) {
      TextView header = (TextView)convertView;

      if (header == null) {
         header = new TextView(mContext);
         header.setTextSize(15);
         header.setBackgroundColor(0xFFFFFFFF);
         header.setTextColor(0xFF222222);
      }

      header.setText(mHeader);

      return header;
   }

   public void onItemClick(AdapterView<?> adapterView, View view, int position,
    long id) {
      Toast.makeText(mContext, "Pos: " + position + " | " + mList.get(position),
       Toast.LENGTH_SHORT).show();
   }
}




Java Source Code List

com.marczych.androidsectionheaders.SectionHeadersAdapter.java
com.marczych.androidsectionheaders.SectionListView.java
com.marczych.androidsectionheaders.Section.java
com.marczych.androidsectionheaders.sample.SampleSectionAdapter.java
com.marczych.androidsectionheaders.sample.SectionHeadersSampleActivity.java