ExpandableListView -UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView

不羁的心 提交于 2019-11-30 05:33:58
Prashant Gami

Seems like Adapterview does not allow adding new view, I encountered same problem

Solve it by replacing following line

convertView  = inflator.inflate(R.layout.child_rows, parent);

to

convertView  = inflator.inflate(R.layout.child_rows, null);

UPDATE

Instead of not using a parent at all, you should simply tell the Inflater not to attach the inflated view to the parent with

convertView = inflator.inflate(R.layout.child_rows, parent, false); 

See also this answer.

The reason is that adapter takes care of attaching views to parent itself.

Note that you can also get this error when your layout xml is invalid.

As were noted above,

Instead of not using a parent at all, you should simply tell the Inflater not to attach the inflated view to the parent with

 convertView = inflator.inflate(R.layout.child_rows, parent, false);     

See also this answer.

The reason is that adapter takes care of attaching views to parent itself.

According to Android Lint your child view should always provide a reference to its parent view when inflated. I had the exact same error in my code. Is was occurring because the TextView was placed inside the ExpandableListView. When I rearranged my xml layout the error stopped appearing.

This error can also be caused because of instant run feature. I was working on listview and because of this error app kept crashing. Uninstalling the app and running again resolved the error.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!