【发布时间】:2015-05-23 22:29:38
【问题描述】:
你好!
我正在尝试在我的主要活动中的 LinearLayout 内创建动态 TextView。该程序(应该是)根据需要将 TextView 从resultrow XML 推送到activity_fivethreeone XML。
parentLayout.addView(textView); 行抛出此错误;
The specified child already has a parent. You must call removeView() on the child's parent first.
我尝试了类似问题的答案,但没有成功。
Fragments - The specified child already has a parent. You must call removeView() on the child's parent first
Call removeView() on the child's parent first
类:
try {
LinearLayout parentLayout = (LinearLayout)findViewById(R.id.linLayout);
LayoutInflater layoutInflater = getLayoutInflater();
View view;
for(int counter=0;counter<=theWeeksList.size();counter++){
view = layoutInflater.inflate(R.layout.resultrow, parentLayout, false);
TextView textView = (TextView)view.findViewById(R.id.resultRow);
textView.setText(theWeeksList.get(counter));
parentLayout.addView(textView);
}
}
我尝试使用removeView(),但无法坚持使用。
任何帮助将不胜感激!
谢谢!
【问题讨论】:
-
嘿不公平!!!我先回答!
标签: java android layout android-studio