Dynamically add text field in android

I am working on an application and should add a text box to the view when the button is selected. How can I do this or add any object dynamically. Which class do I use or what method do I need to call? Thank.

+3
source share
2 answers

You just need to call the method addViewfor the target view. This is 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)

+3
source

One possibility is to define it in your XML layout and set:

android:visibility="gone"

:

TextView myTextBox = (TextView) findViewById(R.id.myTextBoxId);
myTextBox.setVisibility(View.VISIBLE);

:

myTextBox.setVisibility(View.GONE);

+1

Source: https://habr.com/ru/post/1784316/


All Articles