CWitty
CWitty

Reputation: 4536

Dynamically adding textbox in android

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

Answers (2)

dave.c
dave.c

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

wheaties
wheaties

Reputation: 35980

You just need to call the addView method to the target view. It's a method inherited from ViewGroup, see [here][2].

[2]:http://developer.android.com/reference/android/view/ViewGroup.html#addView(android.view.View, android.view.ViewGroup.LayoutParams)

Upvotes: 3

Related Questions