xml - android: Sharing layouts between activites -


suppose wanted create new activity named myactivity.java. how let activity handle view programatically created in mainactivity.java. example, if part of mainactivity:

protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      linearlayout2 = (linearlayout) findviewbyid(r.id.linearlayout2);     image = new imageview(mainactivity.this);      image.setlayoutparams(new linearlayout.layoutparams(layoutparams.wrap_content,layoutparams.wrap_content));     getimages();     = rnd.nextint(muchimages);     setimage();  }  

and wanted create new activity handle image sliding

i asking question because had problem both activities shared same main_activity.xml, when called myactivity part programatically created in main activity not there, because myactivity not see it. how achieve both views created in mainactivity and in myactivity shown in main.xml @ same time? should myactivity create own layout , somehow add main.xml?

forgive me i'm android newbie. ty time

create views in oncreate() dynamically did imageview. add view(s) layout.

linearlayout2.addview(image);     

you can use removeview() when no longer need it.

linearlayout2.removeview(image);   

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? -