【发布时间】:2010-07-18 10:51:08
【问题描述】:
我想为 ExpandableChildView 组件的 childView 充气。
代码:
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: 错误/AndroidRuntime(2738): java.lang.IllegalStateException: 指定的孩子已经有一个父母。 您必须在 首先是孩子的父母。
我该如何解决这个问题?
【问题讨论】:
标签: android android-linearlayout expandablelistview inflate