1

is there any possibility to implement the subheader behaviour as suggested by the google guidelines (see: https://www.google.com/design/spec/components/subheaders.html)? Especially the sticky functionality of the headers is important for me.

I found different libraries on github (e.g. https://github.com/emilsjolander/StickyListHeaders), but i wonder if there is a direct support in the android sdk.

Thanks

Krisna
  • 13
  • 5

1 Answers1

1

If you don't want them sticky, and exactly know what positions the headers are going to be( in your data array), then you could simply use following trick :

header is just another list item type,

so extend BaseAdapter and override following methods :

@Override
getViewTypeCount(){
    return 2;// 1(list items) + 1(for header)
}

@Override
getItemViewType(int position){
if(want to show header at position)
    return 1; // header item
else
    return 0;// regular items
}

@Override
getView(int pos,....)
{
    if(getItemViewType(pos)==0){// regular item
        inflate/reuse convertView; // cast to regular item & bind data
    } else {
        inflate/reuse convertView; // cast to hdr view and bind data 
    }
    return convertView;
}

for detailed analysis you could follow this link : http://cyrilmottier.com/2011/07/05/listview-tips-tricks-2-section-your-listview/

jay shah
  • 903
  • 6
  • 21