Method for filling data in Android listview

Method for filling data in Android listview

Because of multi person development, in order to facilitate the integration of self-developed modules into the main framework, and to reduce the size of APK, XML layout files are required to be used as little as possible. During development, data needs to be displayed in listview. Almost all examples found on the Internet provide layout styles for listview items through XML files, which is very inconvenient.

Can you add dynamic layouts (such as view and LinearLayout) created by yourself through code to listview? Certainly.

In order to provide data to listview, we need to set an adaptation for it. We can inherit from baseadapter and then rewrite its getview method. This method has a parameter convertview. We can set it as our custom view and return it to implement the layout defined in code.

Define a LinearLayout layout, which inherits from view, so it can be returned through getview (Note: do not use the linearlayout.layoutparams parameter for this layout, because listview does not recognize it, it recognizes abslistview layoutparams)

The code is as follows:

Call:

effect:

If you have any questions, please leave a message or go to the community of this site for exchange and discussion. Thank you for reading. I hope it can help you. Thank you for your support to this site!

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
分享
二维码
< <上一篇
下一篇>>