开发者

Displaying empty message for a section in MergedAdapter

I'm using a MergedAdapter to group two custom adapters (ArrayAdapter derived) along with a section header for each one into a single ListView. It is working fine, but now I need to display a TextView saying "No Data" for the section that has no items, e.g. ArrayAdapte开发者_运维百科r is empty.

What's the best approach for this? The code that sets the ListView binding is like this:

ArrayList<ItemOne> firstItems = getFirstGroupItems();
ArrayList<ItemTwo> secondItems = getSecondGroupItems();

ItemOneAdapter firstAdapter = new ItemOneAdapter(this, this.firstItems); ItemTwoAdapter secondAdapter = new ItemTwoAdapter(this, this.secondItems);

MergeAdapter adapter = new MergeAdapter(); adapter.addView(createGroupSeparator(R.string.first_section_header)); //Just creates a TextView adapter.addAdapter(firstAdapter); adapter.addView(createGroupSeparator(R.string.second_section_header)); //Just creates a TextView adapter.addAdapter(secondAdapter);

listView.setAdapter(adapter);


In case of an empty list, you could make the first item read "No Data", but this usually makes the code unmanageable. I would suggest you add an invisible TextView to your screen with the message; this is only displayed when the list is empty.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜