In my ListActivity, I need header and footer views (on the top and bottom of the list) to be used as previous page and next page buttons on my list, respectively, because I want to display only 20 items at a time.
I set my header and foot views by doing:
getListView().addHeaderView(myHeaderView);
getListView().addFooterView(myFooterView);
setListAdapter(adapter);
This works fine, but I need to dynamically remove and add these header and footer views, because some pages of my list may not have a next page button or a previous page button.
The problem is, I cannot call addHeaderView or addFooterView after I have called setListAdapter.
Is there a way around this?
Why not just collapse the header and footer to zero height, or gray out the buttons (even better).
And the best user experience, in my opinion, would be to dynamically load more items when needed (i.e. upon scroll), like the built-in Gmail app does.
Yes, this is a bug or oversight in the ListView
component. You can work around this by writing your own WrapperListAdapter
that handles adding and removing fixed list items, but I can tell you it's not entirely straightforward to do.
Alternatively — and much easier — you could add a fixed component above or below the ListView
where you place the next and previous buttons.
How about reset the adapter at every time you need to add header view, like this way:
ListView.FixedViewInfo headerInfo = getListView().new FixedViewInfo();
headerInfo.isSelectable=false ;
headerInfo.view = feedInfoView;
headerInfos.add(headerInfo);
headerViewListAdapter = new HeaderViewListAdapter(headerInfos,null,adapter);
getListView().setAdapter(headerViewListAdapter);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With