I was wondering how I can program a button in my android application to create/make a new button in a different xml/class?
Can someone help me with this?
Any help appreciated.
Thanks.
I was wondering how I can program a button in my android application to
Share
I can see two approches to this.
Create the button you want to be enabled but the other button in your XML layout file as usual. Then set it’s
android:visibilityparameter togoneorinvisible. Now you can control wether or not the view will be visible or not from code. UserView.setVisibility()to change that.Check this link for more details: http://developer.android.com/reference/android/view/View.html#setVisibility(int) (it also explains the difference between
invisibleandgone)You can add a view to a
ViewGroupdynamically from code. In order to do that you can create the button you want from code –... new Button(...)...and then adding it to your desiredViewGroupby callingViewGroup.addView(...).More on that topic: Android: Add a view to a specific Layout from code