Does Android have a Table like Adapter for ListView

前端 未结 4 1628
南方客
南方客 2021-01-05 02:48

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 l

相关标签:
4条回答
  • 2021-01-05 02:49

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

    0 讨论(0)
  • 2021-01-05 03:02

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

    0 讨论(0)
  • 2021-01-05 03:03

    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.

    0 讨论(0)
  • 2021-01-05 03:05

    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

    0 讨论(0)
提交回复
热议问题