Hello!
I'm trying to create dynamic TextViews inside a LinearLayout within my main activity. The program is (supposed to be) pushing out TextView's from resultrow
XML to activity_fivethreeone
XML as required.
The line parentLayout.addView(textView);
is throwing this error;
The specified child already has a parent. You must call removeView() on the child's parent first.
I've tried answers from similar questions but getting no wins.
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
class:
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);
}
}
I was trying to use removeView()
but couldn't get it to stick.
Any help will be much appreciated!
Thanks!