您的位置:首页 > 编程语言 > Java开发

java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView

2015-10-28 12:53 645 查看
原文链接

AdapterView 的子类 比如ListView 不能在layout中添加 子布局,或者在 代码中添加子布局。

<ListView // .. other attributes>
<// other views <-- notice the children of the ListView tag
</ListView>


这种布局方式,是会报错的。

正确做法:

<ListView // .. other attributes />
< // other views


也不能通过 addView方法

listViewReference.addView(anotherView); // <-- don't do it


还有一种方式也会出现这个错误

在LayoutInflater.inflate方法中,不能把listivew座位第二个参数,举例来说

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


这种方法也会报错

应该替换为:

convertView  = inflator.inflate(R.layout.child_rows, parent, false);//correct
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  布局 listiview addview