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

前端 未结 5 703
孤独总比滥情好
孤独总比滥情好 2020-12-29 18:02

I am implementing Expandable List view in android and i am getting the above titled error. Please help me.

Main activity is -

package com.expand;

i         


        
5条回答
  •  忘掉有多难
    2020-12-29 18:14

    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.

提交回复
热议问题