android - How to create button dynamically from one activity to another activity -


i creating android application consists of adding button dynamically.here when click button in 1 activity button dynamically created activity. possible create button when clicking button in 1 activity create button in activity.please me this.

package com.example.dynamicbutton;  import android.app.activity; import android.content.intent; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.button;  public class mainactivity extends activity {      button add_button;     activity_2 act_child;       @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         add_button = (button)findviewbyid(r.id.button_add);         add_button.setonclicklistener(new view.onclicklistener() {              public void onclick(view v) {                   intent invisible = new intent(mainactivity.this,activity_2.class);                 startactivity(invisible);                 act_child.visible.setvisibility(view.gone);              }         });     }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.main, menu);         return true;     }      @override     public boolean onoptionsitemselected(menuitem item) {         // handle action bar item clicks here. action bar         // automatically handle clicks on home/up button, long         // specify parent activity in androidmanifest.xml.         int id = item.getitemid();         if (id == r.id.action_settings) {             return true;         }         return super.onoptionsitemselected(item);     } } 

the solution simple.do following in first activity. if button clicked use following.

intent invisible = new intent(mainactivity.this,activity_2.class); //here add line .putextra("visibility", "1");                 startactivity(invisible); 

else

intent invisible = new intent(mainactivity.this,activity_2.class);     //here add line     .putextra("visibility", "0");                     startactivity(invisible); 

in second activity:

string visibility = getintent().getstringextra("visibility"); if (visibility.equals("1")){  act_child.visible.setvisibility(view.visible); }else{  act_child.visible.setvisibility(view.gone); } 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -