我想膨胀ExpandableChildView组件的childView。ExpandableListView中的LinearLayout
代码:
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
View v = convertView;
LinearLayout linearOpt = themesOptions.get(childPosition);
if(v == null) {
v = mInflater.inflate(R.layout.itemrow, null);
}
LinearLayout ll = (LinearLayout) v.findViewById(R.id.root);
ll.addView(linearOpt);
return v;
}
哪里linearOpt是含有大量的LinearLayout对象,我已经实例化的载体。
private void prepareThemes(){
View v = mInflater.inflate(R.layout.widget_configure, null);
LinearLayout theme = (LinearLayout) v.findViewById(R.id.themeLayout);
LinearLayout color = (LinearLayout) v.findViewById(R.id.colorLayout);
LinearLayout trans = (LinearLayout) v.findViewById(R.id.transpLayout);
themesOptions.add(theme);
themesOptions.add(color);
themesOptions.add(trans);
}
这是R.layout.itemrow XML:
但我收到此错误:
07-18 10:48:49.740: ERROR/AndroidRuntime(2738): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
我怎么能解决这个问题?