I am trying to add multiple views of the same layout. however, when doing the below code I am getting Exception: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
What am i doing wrong? thanks!
class GetTrackTimer extends TimerTask {
Activity act;
View RootView;
public GetTrackTimer(Activity ctx, View RootView)
{
this.act = ctx;
this.RootView = RootView;
}
@Override
public void run() {
act.runOnUiThread(new Runnable() {
@Override
public void run() {
if (TrackItems.getInstance().items == null)
return;
LinearLayout items = (LinearLayout) RootView.findViewById(R.id.itemslist);
LayoutInflater inflater = (LayoutInflater) act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for (int i = 0; i < TrackItems.getInstance().items.length; i++)
{
View itemView = inflater.inflate(R.layout.track_item,null);
TextView tv= (TextView)itemView.findViewById(R.id.itemName);
tv.setText(TrackItems.getInstance().items[i].Item.ID + "");
items.addView(tv);
}
}
});
}
}