shohreh
shohreh

Reputation: 526

android: how add section footer to a list

I'm using SeperatedListAdapter available here: http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/

but I want to create a list with footer for each section. i don't know how should i do this. any other solution to create a section-List with footer for each section will be helpful.

edited:

now i change the adapter as bellow:

footers = new ArrayAdapter<String>(context, R.layout.footer_layout);
    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() + 2;  
        return total;  
    }  


//@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() + 2;  

        // check if position inside this section  
        if(position == 0) return headers.getView(sectionnum, convertView, parent);  
        if(position < size-1) return adapter.getView(position - 1, convertView, parent);
        if(position == size -1)  return headers.getView(sectionnum, convertView, parent); 

        // otherwise jump into next section  
        position -= size;  
        sectionnum++;  
    }  
    return null;  
}  

but i get index exception

Upvotes: 1

Views: 1250

Answers (1)

oscar
oscar

Reputation: 647

You can just create a new layout that is returned in getView (in your adapter) as the last position in each section. (instead of first in each section)

I believe that is the similar to the solution that the SeperatedListAdapter uses.

Upvotes: 1

Related Questions