how can i add a view like textview from another layout to current layout in android -


i want create layout form programmatically . example want add view textview in form couple of times . created layout has textview want add textview couple of times in current layout .

public class fileform extends activity {      linearlayout lin_main;     textview tv_grouptitle;     layoutinflater lyotinf;     view viw_allitems;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_file_form);         lin_main = (linearlayout) findviewbyid(r.id.lin_main);         lyotinf = (layoutinflater) getsystemservice(context.layout_inflater_service);         viw_allitems = lyotinf.inflate(r.layout.item,null);         tv_grouptitle = (textview) viw_allitems.findviewbyid(r.id.tv_grouptitle);          int int_groupnum = 0;         list<integer> int_emnumingroup = new arraylist<integer>();;         emmanager emm = null;         emm = emm.getinstance();              element emnode = emm.getem();         element  emg = null;         element  eme = null;         nodelist group = null;         nodelist emlist = null;         group = emnode.getchildnodes();         int_groupnum = group.getlength();         lin_main.removeallviews();          (int i=0;i<int_groupnum;i++)         {             emlist = group.item(i).getchildnodes();             int_emnumingroup.add(emlist.getlength());              (int j=0;j<int_emnumingroup.get(i);j++)             {                 eme = (element) emlist.item(j);                 for(int att=0;att<integer.parseint(eme.getattribute("num"));att++)                 {                     tv_grouptitle.settext(eme.getnodename());                     lin_main.addview(tv_grouptitle);                 }             }         }     }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.file_form, menu);         return true;     }  } 

but there error .

you must create textview programmatically (textview text = new textview(context)), not findviewbyid , must in for, this:

    (int j=0;j<int_emnumingroup.get(i);j++)             {                  eme = (element) emlist.item(j);                  for(int att=0;att<integer.parseint(eme.getattribute("num"));att++)                 {                      textview tv_grouptitle = new textview(this)                      tv_grouptitle.settext(eme.getnodename());                      lin_main.addview(tv_grouptitle);                  }              } 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -