android - Dynamically Add and Remove Views from Layout -


i'm working on 1 demo project in had create 1 xml file containing views imageview, edittext. i'm loading xml file on framelayout @ runtime. @ 1 point want remove views , again want display them, used removeview() method on button click not work me,,please tell me right way it..

       public class demo extends fragment implements onclicklistener, ontouchlistener{     //declaration of framelayout     framelayout f;     //declaration of imageview     imageview imageview;     view view, framelayoutview;     file file;     edittext etcardname, edittextusername,edittextusesrmobnumber,edittextusesremailid,edittextusesraddress;     textview dialogtesting;      @override      public view oncreateview(layoutinflater inflater, viewgroup container,      bundle savedinstancestate) {         view = inflater.inflate(r.layout.activity_modify_card ,container, false);         framelayoutview = inflater.inflate(r.layout.frame_layout_data ,container, false);         captureimageinitialization();         initialize();         return view;        }      // initialization of views components      private void initialize() {             f=(framelayout)view.findviewbyid(r.id.framelayout);             button btneditcardreset=(button)view.findviewbyid(r.id.buttonresetcard);             btneditcardreset.setonclicklistener(this);             bundle bundle = this.getarguments();             int myint;             myint = bundle.getint("position");              imageview=(imageview)framelayoutview.findviewbyid(r.id.imageviewicon);             edittextusername=(edittext)framelayoutview.findviewbyid(r.id.modifycardedittextusername);             edittextusesrmobnumber=(edittext)framelayoutview.findviewbyid(r.id.edittextmobilesnumber);             edittextusesremailid=(edittext)framelayoutview.findviewbyid(r.id.edittextemailid);             edittextusesraddress=(edittext)framelayoutview.findviewbyid(r.id.edittextaddress);              imageview.setontouchlistener(this);             edittextusername.setontouchlistener(this);             edittextusesrmobnumber.setontouchlistener(this);             edittextusesremailid.setontouchlistener(this);             edittextusesraddress.setontouchlistener(this);             f.addview(framelayoutview);            }     @override     public void onclick(view v){          if(v.getid()==r.id.buttonresetcard){                  if(framelayoutview.getparent()!=null){                  f.removeallviews();                  }                  f.addview(framelayoutview);                   }       } 

sorry forgot tell provided ontouchlistener can move views anywhere in layout. when press reset button views should move original location means @ on first load..

you can use

imageview.setvisibility(view.gone);

and

imageview.setvisibility(view.visible);

on particular event


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -