ListView with sections and custom backgrounds for each section
For ur ref , I have implemented the same thing in the following application
this is how I have implemented, 1) kept all the data in an Arraylist. For example:
private String HEADING_TAG="heading";
private String ITEM_TAG="item" ;
ArrayListdata=
new ArrayList();
data.add( HEADING_TAG+"@selector");
data.add( ITEM_TAG+ "@item1")
/* in the above line "heading" is a tag, just to know that the
following listitem is a heading.
"@" is a separator using which we wl split the string later in
the adapter*/
2) Now implement a custom adapter and overide getView() method. Note: pass the length of the list to the adapter. 3) access the data list inside getView() method, an arguement called position will be available in getView method. Use that variable to iterate list. For Example:
getView(....,....,int pos,....)
{
String temp[]= data.get(position).split("@");
if(temp[0].equals( HEADING_TAG ))
{
// change the background to the layout which u r inflating.
// Set the heading to the textview or what ever view u defined
//the layout
}
else if (temp[1].equals( ITEM_TAG ) )
{
// set the item to the view
}
}
Hope this helps...
.
stackoverflow.comm
No comments:
Post a Comment