曾经尝试过ListView和其他组件组合在一起使用,结果Android 1.6版本上是没问题,但Android 1.5版本却一直报错。后来经过和sanvi的讨论,发现其实实现起来非常简单,因为,Listview和ExpandableListView都可以为其设置“表头组件”和“表尾组件”,即: addHeaderView 和addFooterView,然后要记得做一下registerForContextMenu(listView),就大功告成了!本人例子中是在Activity的onCreate方法中添加了下来代码。
// 增加列表头元素
ExpandableListView listView = getExpandableListView();
listView.setCacheColorHint(R.color.hint);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.peoplelist_head, null);
listView.addHeaderView(view);
registerForContextMenu(listView);
setListAdapter(mAdapter);
listView.setBackgroundResource(R.drawable.default_bg);
其中peoplelist_head便为需要添加到列表上面的布局文件。
在底部添加方法为:
listView.addFooterView(view);
本文介绍了如何在Android应用中将ListView与其他组件如表头和表尾组件组合使用的方法,并提供了一个具体的示例代码,展示了如何通过addHeaderView和addFooterView方法来实现这一功能。
863

被折叠的 条评论
为什么被折叠?



