android - How to use addRule() with a tag dynamically inside a loop it takes Exception when inflating View? -


i have loop add variable number of views relativelayout, , want set rules below, problem i'm using tags name objects dynamically, , use addrule() method need use id, tried set id every time loop runned , it's not first time.

this code:

for(int = 1; <= knumberofviews; i++){     view = new myview(context);     relativelayout.layoutparams params = new layoutparams(kviewwidth, kviewheight);     params.setmargins(kmarginleft, kmargintop, kmarginright, kmarginbottom);     params.addrule(center_horizontal);     if (i != 1){         myview view = (myview)view.findviewwithtag(i-1);         view.setid(i);         params.addrule(relativelayout.below, view.getid());     }     view.settag(i);     view.setbackgroundcolor(color.green);     system.out.println("view " + +" added correctly");     addview(view, params); } 

how can solve it?

edit:

05-18 14:57:19.549: e/androidruntime(5500): fatal exception: main 05-18 14:57:19.549: e/androidruntime(5500): java.lang.runtimeexception: unable start activity componentinfo{me.gabrielesteban.app/me.gabrielesteban.app.myrelativelayouttest}: android.view.inflateexception: binary xml file line #7: error inflating class me.gabrielesteban.app.gd.myrelativelayout 05-18 14:57:19.549: e/androidruntime(5500):     @ android.app.activitythread.performlaunchactivity(activitythread.java:2307) 05-18 14:57:19.549: e/androidruntime(5500):     @ android.app.activitythread.handlelaunchactivity(activitythread.java:2357) 05-18 14:57:19.549: e/androidruntime(5500):     @ android.app.activitythread.access$600(activitythread.java:153) 

edit 2:

i think problem in following line myview view = (myview)view.findviewwithtag(i-1);, line correct?

i reviewed code again , read how call findviewwithtag in oncreate() method of activity? , see when call findviewwithtag() method put same object i'm finding before method, result don't find object inside object tag, thing have delete part.

myview view = (myview)view.findviewwithtag(i-1); //bad way find view  myview view = (myview)findviewwithtag(i-1); //good way find view tag 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -