实际上这不是listview而是expandablelistview,但这并不重要。通常我会这样做:
<ScrollView >
<LinearLayout>
<ExpandableListView ... />
<TextView ... />
</LinearLayout>
</ScrollView>
…但我读过在scrollview中使用listview很费劲。我试图通过修改expandListAdapter(getChildView())来解决这个问题:
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent) {
if(isLastChild){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.extra_info_bottom, null);
}
else{
//get normal item view
}
return view;
}
但这样我只能把孩子附加到组中。如何在任何组的底部附加linearlayout?
最佳答案
只需添加以下代码,即可在最后一个listview块添加线性布局。
View footerView = ((LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.listfooter, null, false);
itemlist.addFooterView(footerView);
其中ListFooter是XML文件,您可以在其中定义布局控件。