android - Dynamically add or remove views -


for project need functionality dynamically add , remove views(textedit or buttons, etc).

i saw similar functionality in android "add contact" screen, plus button add new fields , minus button delete fields.

i found editcontactactitivity.java file behind "add contacts".

i tried find methods called when plus or minus buttons pressed unable find it, seems "add contact" code spreaded on multiple files. having difficulty understanding android source code because documentation unavailable.
advice?

you can add , remove views calling .add() or .remove() on reference main layout , passing view wish add or remove;

here simple example of oncreate method demonstrates adding , removing button:

public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);      linearlayout mymainlayout = (linearlayout)findviewbyid(r.id.yourmainlayout);     button b = new button(this);     //you can have b.setxxx calls here set text, view, click listeners etc...     mymainlayout.add(b);        //to remove     mymainlayout.remove(b);  } 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -