How to add dynamically a Layout into TableRow

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

How to add dynamically a Layout into TableRow

Postby Luser_k » Thu Apr 22, 2010 9:28 am

Hi,

need urgent help.

I create a dynamic Table with 7 TableRows.

So I will add to my TableRows RelativeLayouts and in them 3 ImageViews, so that I can align them.

But when I create a RelativeLayout and add into this RelativeLayout images,
I get an: IllegalStateExeption

Code: Select all
The specified child already has a parent. You must call removeView() on child´s parent first.


My Code:

Code: Select all
...

for(int i=0;i<3;i++){

tr = new TableRows(this);
tr.setId(...);
tr.setLayoutParams(new TableRow.LayoutParams....);

   for(int k=0;k<3;k++){

    rl = new RelativeLayout(this);
    rl.setId(...);
    ...
    iv = new ImageView(...);
    iv.setId(..);
    iv.setImgeResource(...);

    rl.add(iv);

    tr.add(rl);
   }

table.addView(tr,....);

}

...



How can I solve this problem?

I need RelativeLayout to align my images.
Luser_k
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Apr 07, 2010 2:56 pm

Top

Postby Luser_k » Thu Apr 22, 2010 10:13 am

Luser_k
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Apr 07, 2010 2:56 pm

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 11 guests