title: creating a custom Array Adapter for SeperatedListAdapter Android
body: <p>Hi I'm using a SeparatedListAdapter to add sections to a listView. an i'm trying to implement a custom Array adapter to populate each item in the section by passing in a JSONArray of JSONObjects and from this adding strings to an ArrayList. However when i run the app the headers work fine but its not displaying any of the items under each header.</p>
  
  <p>heres the SeparatedListAdapter</p>
  
  <pre><code>import java.util.LinkedHashMap;
  import java.util.Map;
  
  import android.content.Context;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.Adapter;
  import android.widget.ArrayAdapter;
  import android.widget.BaseAdapter;
  
  public class SeparatedListAdapter extends BaseAdapter {
  
      public final Map&lt;String,Adapter&gt; sections = new LinkedHashMap&lt;String,Adapter&gt;();
      public final ArrayAdapter&lt;String&gt; headers;
      public final static int TYPE_SECTION_HEADER = 0;
  
      public SeparatedListAdapter(Context context) {
          headers = new ArrayAdapter&lt;String&gt;(context, R.layout.list_header);
      }
  
      public void addSection(String section, Adapter adapter) {
          this.headers.add(section);
          this.sections.put(section, adapter);
      }
  
      public Object getItem(int position) {
          for(Object section : this.sections.keySet()) {
              Adapter adapter = sections.get(section);
              int size = adapter.getCount() + 1;
  
              // check if position inside this section 
              if(position == 0) return section;
              if(position &lt; size) return adapter.getItem(position - 1);
  
              // otherwise jump into next section
              position -= size;
          }
          return null;
      }
  
      public int getCount() {
          // total together all sections, plus one for each section header
          int total = 0;
          for(Adapter adapter : this.sections.values())
              total += adapter.getCount() + 1;
          return total;
      }
  
      public int getViewTypeCount() {
          // assume that headers count as one, then total all sections
          int total = 1;
          for(Adapter adapter : this.sections.values())
              total += adapter.getViewTypeCount();
          return total;
      }
  
      public int getItemViewType(int position) {
          int type = 1;
          for(Object section : this.sections.keySet()) {
              Adapter adapter = sections.get(section);
              int size = adapter.getCount() + 1;
  
              // check if position inside this section 
              if(position == 0) return TYPE_SECTION_HEADER;
              if(position &lt; size) return type + adapter.getItemViewType(position - 1);
  
              // otherwise jump into next section
              position -= size;
              type += adapter.getViewTypeCount();
          }
          return -1;
      }
  
      public boolean areAllItemsSelectable() {
          return false;
      }
  
      public boolean isEnabled(int position) {
          return (getItemViewType(position) != TYPE_SECTION_HEADER);
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          int sectionnum = 0;
          for(Object section : this.sections.keySet()) {
              Adapter adapter = sections.get(section);
              int size = adapter.getCount() + 1;
  
              // check if position inside this section 
              if(position == 0) return headers.getView(sectionnum, convertView, parent);
              if(position &lt; size) return adapter.getView(position - 1, convertView, parent);
  
              // otherwise jump into next section
              position -= size;
              sectionnum++;
          }
          return null;
      }
  
      public long getItemId(int position) {
          return position;
      }
  
  
  
  }
  </code></pre>
  
  <p>here is my custom array adapter when i log it out it only runs the log 1= and never actually logs out 2= which suggests to me that my custom array adapter isn't getting the view but i'm not sure why.</p>
  
  <pre><code>public class ContactArrayAdapter extends ArrayAdapter&lt;String&gt; {
  
  
  
      // declaring our ArrayList of items
      private JSONArray contact;
      private ArrayList&lt;String&gt; contactName;
      private ArrayList&lt;String&gt; accessLevel;
      private ArrayList&lt;String&gt; docModified;
      private ArrayList&lt;String&gt; fileName;
      private String bgColor;
      public Typeface myTypeFace;
      /* here we must override the constructor for ArrayAdapter
      * the only variable we care about now is ArrayList&lt;Item&gt; objects,
      * because it is the list of objects we want to display.
      */
      public ContactArrayAdapter(Context context, int layoutResourceId, JSONArray Contact, String bgColor,Typeface font) {
          super(context, layoutResourceId);
          this.contact = Contact;
          this.bgColor = bgColor;
          myTypeFace = font;
          Log.v("CAA", " 1 = ");
      }
  
      /*
       * we are overriding the getView method here - this is what defines how each
       * list item will look.
       */
      public View getView(int position, View convertView, ViewGroup parent){
          Log.v("CAA", " 2 = ");
          // assign the view we are converting to a local variable
          View v = convertView;
  
          // first check to see if the view is null. if so, we have to inflate it.
          // to inflate it basically means to render, or show, the view.
          if (v == null) {
              LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              v = inflater.inflate(R.layout.document_cell, parent);
              Log.v("CAA", " 3 = ");
          }
  
          JSONObject singleContactDict;
  
          for (int i=0; i&lt;contact.length(); i++){
              Log.v("CAA", " 4 = ");
              Log.v("CAA", " contact = " + contact);
              try {
                  singleContactDict = contact.getJSONObject(i);
  
              Log.v("CAA", "Contact singleContactDict " + i +"= " + singleContactDict);
              contactName.add(singleContactDict.getString("first_name") + " " +  singleContactDict.getString("last_name"));
              } catch (JSONException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }           
          }
          /*
           * Recall that the variable position is sent in as an argument to this method.
           * The variable simply refers to the position of the current object in the list. (The ArrayAdapter
           * iterates through the list we sent it)
           * 
           * Therefore, i refers to the current Item object.
           */
          String title = contactName.get(position);
          String types = accessLevel.get(position);
          String modified = docModified.get(position);
          String extension = fileName.get(position);
  
          Log.v("CAA","DocumentArrayAdapter, = " + title);
  
          if (title != null) {
  
              // This is how you obtain a reference to the TextViews.
              // These TextViews are created in the XML files we defined.
  
              TextView docTitle = (TextView) v.findViewById(R.id.name);
              docTitle.setTypeface(myTypeFace);
              docTitle.setTextColor(Color.parseColor(bgColor));
              TextView docType = (TextView) v.findViewById(R.id.doctype);
              docType.setTypeface(myTypeFace);
              TextView docMod = (TextView) v.findViewById(R.id.modified);
              docMod.setTypeface(myTypeFace);
  
              ImageView docImage = (ImageView) v.findViewById(R.id.docicon);
  
  
  
              // check to see if each individual textview is null.
              // if not, assign some text!
              if (docTitle != null){
                  docTitle.setText(title);
              }
  //          if (accessLevel != null){
  //              docType.setText(types);
  //          }
  
  
  
      }
          return v;
      }
  
  }
  </code></pre>