How to add multiple header views in a ListView

后端 未结 3 786
时光说笑
时光说笑 2021-02-04 18:35

I\'ve a custom adapter for my ListView I want to add project names as the headers to my work requests. Adding a single header works just fine but I\'m not sure how

3条回答
  •  没有蜡笔的小新
    2021-02-04 19:12

    I don't think what you want to do is possible the way you are trying to do it. When you use addHeaderView it wraps your ListAdapter in HeaderViewListAdapter. I looked at the docs for it here and that seems to imply that you could have multiple headers, but they would all be at the top (duh, header).

    It sounds like what you actually want is seperators...

    You could use CommonWare's MergeAdapter. It will let you insert adapters and views (in whatever order you wish) and present them all as a single adapter to a listview. You just hand it headers and adapters for each section of content and then set it to your list.

    Pseudo-code example:

    myMergeAdapter = new MergeAdapter(); 
    myMergeAdapter.addView(HeaderView1); 
    myMergeAdapter.addAdapter(listAdapter1); 
    myMergeAdapter.addView(HeaderView2); 
    myMergeAdapter.addAdapter(listAdapter2); 
    setListAdapter(myMergeAdapter); 
    

提交回复
热议问题