java - add linearlayout dynamically into a Relativelayout -


i have code , want add checkboxes dynamically inside linearlayout nested inside scrollview nested inside relativelayout( relativelayout->scrollview->linearlayout->my chechboxes)

li = (relativelayout) findviewbyid(r.id.mainlayout);     scrollview sv = new scrollview(this); final linearlayout ll = new linearlayout(this); ll.setorientation(linearlayout.vertical); li.addview(sv); sv.addview(ll); for(int = 0; < 20; i++) {     checkbox cb = new checkbox(getapplicationcontext());     cb.settext("i'm dynamic!");     ll.addview(cb); } this.setcontentview(sv); 

but error:

03-12 20:32:14.840: e/androidruntime(945): caused by: java.lang.illegalstateexception: specified child has parent. must call removeview() on child's parent first. 

my relativelayout declared in xml file how can fix this?

this.setcontentview(sv); 

this tries add scrollview framelayout android.r.id.content, made li parent of sv... hence "the specified child has parent."

i believe can remove this.setcontentview(sv); since looks want add scrollview (et al.) relativelayout, not replace entire existing layout.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -