当前位置: 代码迷 >> 综合 >> ListView adapter getView 报错: addView(View, LayoutParams) is not supported in AdapterView
  详细解决方案

ListView adapter getView 报错: addView(View, LayoutParams) is not supported in AdapterView

热度:82   发布时间:2023-12-16 14:23:43.0
04-24 15:58:38.768 24891-24891/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                   Process: com.example.kodulf.listviewyouhuademo, PID: 24891

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


报错原因是:后面的inflate 不应该是parent,应该是null

convertView = LayoutInflater.from(context).inflate(R.layout.item,parent);


解决办法:

convertView = LayoutInflater.from(context).inflate(R.layout.item,null);


  相关解决方案