---
title: "【BUG解决】Cannot add header view to list -- setAdapter has already been called."
author: "libo19881179"
date: "2012-01-05T09:45:20Z"
tags: []
categories: ["移动开发"]
slug: "bug-cannot-add-header-view-to-list-setadapter-has-already-been-called"
draft: false
lastmod: "2012-03-15T14:28:09Z"
id: 1335696
url: "https://androiddada.iteye.com/blog/1335696"
---

今天在为ExpandableListView addHeaderView（加头view），运行报错：

Cannot add header view to list -- setAdapter has already been called.

 

提示我已经设置了适配器，原来addHeaderView（View v）方法 只能在父控件 setAdapter之前调用！

[http://androiddada.iteye.com/](http://androiddada.iteye.com/)

仔细想想也很容易解释，addHeaderView是为list加入 头视图，而setAdapter是为控件匹配内容。哪有先匹配了内容，再插入view的道理，皮之不存毛将焉附？