【BUG解决】Cannot add header view to list -- setAdapter has already been called.

今天在为ExpandableListView addHeaderView(加头view),运行报错:

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

 

提示我已经设置了适配器,原来addHeaderView(View v)方法 只能在父控件 setAdapter之前调用!

http://androiddada.iteye.com/

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

 

 

你可能感兴趣的:(android,bug)