Home » Android » Does Android have a Table like Adapter for ListView

Does Android have a Table like Adapter for ListView

Posted by: admin June 15, 2020 Leave a comment


I’m using a ListView to show a list of items. These items are in a table format with columns and rows. Is there a table like adapter to make sure all the columns and rows line up? I know this brings in the complexity of how large each column should be, what to do with cut off text, and other things. I’m just curious if there is currently and adapter hiding somewhere for this task. Or maybe even another control?

How to&Answers:

The point of using ListView is to be able to scale to larger data sets by not having to create and layout views for all of the items up-front. Because of this, your request fundamentally conflicts with how ListView works — ListView simply doesn’t know how all of its items will layout, so there is no way for it to automatically make sure they align in some way.

You can ensure they align yourself just by writing the item layout appropriately. For example, very often in the UI you will have an icon followed by a label. If you ensure the icon is a specific size, then all of the list items will align. If you are dealing with elements that are more dynamic like text, you could do the same thing by enforcing up-front a specific width for those elements.

If you really want to have the UI compute the element sizes dynamically and align all of the rows based on them, that is what TableLayout does. It can do this because it always has all elements there to layout together. If you want to allow scrolling in it, you can wrap that in a ScrollView like another poster suggested. Just be aware that this approach will quickly fall apart as your number of rows increases significantly.


I was able to make TableLayout to behave like ListView (at least visually). Here is my answer.


There is GridView for that, but afaik it doesn’t work with columns and rows. Luckily you seem to have been expecting some complexity 🙂


You can use a ListView or a ListFragment and populate items using each time a single TableRow inside a TableLayout (maybe using android:stretchColumns=”0″)

you’ll have a TableLayout per line, so it’s probably inefficient but it does what you are trying to do