Method of implementing adaptive table in listview improved by Android

The previous article introduced the method of using GridView to realize tables. This article will talk about how to use listview to realize adaptive tables. GridView is easier to implement adaptive tables than listview, but the size of each cell in GridView is fixed, and the size of each cell can be customized for the tables implemented by listview, but the implementation of adaptive tables will be more complex (mainly due to different cell sizes). In addition, the table implemented by GridView can be located in a specific cell, while the table implemented by listview can only be located in the table row. Therefore, it is still the old saying: select GridView or listview to implement the table according to the specific use environment.

Let's take a look at the effect diagram of the program running in this paper, as shown in the following figure:

The listview table implemented in this paper can have different cell sizes. Text (textview) or picture (ImageView) can be used as cell data, and there is no need to define XML implementation style in advance (the fundamental goal of adaptation). Because the listview is placed in the horizontal Scrollview, it can also well adapt to the width of the data table with many columns / long column data.

The source code of main.xml is as follows:

The source code of the main class testmylistview.java is as follows:

The class tableadapter.java code of listview adaptive implementation table is as follows:

Note here: TableCell is a class of cells, tablerow is a class of table rows, and tablerowview is a component that implements table rows. Implementation steps: TableCell -- > tablerow (tablerowview) - > listview

I hope the examples described in this article can be helpful for everyone to develop Android projects.

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