Android - Textview added when button pressed
I want to know if it is possible to make a textview load on the screen when a button is pressed...
I do not want to make the textview invisible, then visible when the button is pressed, I want it to act开发者_JS百科ually (dynamically) appear on the screen.
Any help?
You have to dynamically add view in a parent view for that you have to create a view
for example
You have a parent view name layParent
and you want to add textview
inside layParent
for first make a textview using code like this
TextView tv = new TextView(context)
tv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
tv.setText("textview");
layParent.addView(tv);
write this code in button click event so that you can add text-view as many as you click on button
for more information see this question
Android - Dynamically Add Views into View
精彩评论