Method of dynamically adding view in Java

In general, most of us write the layout directly in XML files, but sometimes we need to add the layout dynamically with code. For example, I made a display of the number of pages of viewpager yesterday. When there is no content, we give textview to clear, and some content is added dynamically with java code.

1. Write code, generate a view, and add it to the LinearLayout.

2. Display textview according to the page number of viewpager

The for loop is used to judge whether there is a textview in the LinearLayout. If it does not exist, a textview is created, and then the data of the textview can be changed dynamically.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>