I have an activity where linearlayouts are added dynamically into a base linearlayout. You'll understand from my code, but I'm trying to resuse the same "addBlock" method to add more data in the activity. If you can help me out with this, I would appreciate it! Thanks!
My code:
private void addData01() {
wii=R.drawable.img01;
d=getString(R.string.one_d); //this is later set to a seperate textview
//START OF BLOCK 1//
b1_t = getString(R.string.Title1);
b1 = new String[]{"DATA WILL GO HERE"};
b1_i = new String[]{"DATA WILL GO HERE"};
addBlock();
//START OF BLOCK 2//
b1_t = getString(R.string.Title2);
b1 = new String[]{"MORE DATA WILL GO HERE"};
b1_i= new String[]{"MORE DATA WILL GO HERE"};
addBlock();
}
private void addBlock() {
LayoutInflater inflater = LayoutInflater.from(this);
for(int i = 0 ; i < b1.length ; i++)
{
View childView = inflater.inflate(R.layout.two_row, null,false);
TextView tv = (TextView)childView.findViewById(R.id.one);
TextView tv2 = (TextView)childView.findViewById(R.id.two);
tv.setText(Html.fromHtml(b1[i]));
tv2.setText(Html.fromHtml(b1_i[i]));
b_ll.addView(b1t);
b_ll.addView(childView);
}
}
However when I do this I get the following error:
08-05 21:18:15.462: E/AndroidRuntime(4241): Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
I have tried looking at this How to add same view to parent multiple times by inflating it only once but the solutions there did not seem to work