Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Android have a Table like Adapter for ListView

Tags:

android

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?

like image 990
Spidy Avatar asked Apr 22 '11 15:04

Spidy


2 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.

like image 71
hackbod Avatar answered Nov 11 '22 07:11

hackbod


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

like image 42
GrAnd Avatar answered Nov 11 '22 07:11

GrAnd