开发者

How to display ListView items with numerical and then Alphabetical header sections in android

I have a requirement to display ListView items in numerical and then Alphabetical header sections. But my requirement is first it should display ListView items with numerical header sections and then after it should display the ListView items in the alphabetical header sections. But i got the mixed result like below.

A,1,B,2,C,3(header sections)

But my requirement is as 开发者_StackOverflow社区follows

1,2,3,A,B,C(along with listView items below the header sections)


You can use my Simple Section Adapter to do that. Just sort your list in ascending order, starting from 1...N, A-Z and create a Sectionizer with the following code.

public class NumericAndAlphabetSectionizer implements Sectionizer<YourObjectType> {

    @Override
    public String getSectionTitleForItem(YourObjectType instance) {
        return instance.getName().toUpperCase().substring(0, 1);
    }
}

Once you create the Sectionizer, simply wrap your custom adapter and you are done.

sectionAdapter = new SimpleSectionAdapter<YourObjectType>(context, 
            yourAdapter, R.layout.section_header, R.id.title, 
            new NumericAndAlphabetSectionizer());

That's it. You are done.


You need your adapter to return the list in whatever order you want. The getView method should return the appropriate item based on the value of the position parameter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜