Reputation: 4536
I am working on an app and need to add a textbox to the View when a button is selected. How can I do that or add any object dynamically. What class do I use or what method do I need to call? Thanks.
Upvotes: 3
Views: 2219
Reputation: 10908
One possibility is to define it in your layout XML, and set:
android:visibility="gone"
Then in your code you can do:
TextView myTextBox = (TextView) findViewById(R.id.myTextBoxId);
myTextBox.setVisibility(View.VISIBLE);
and to hide it again:
myTextBox.setVisibility(View.GONE);
Here is the documentation
Upvotes: 1