Fancy dynamic list in Android: TableLayout vs ListView

Posted by Ralkie on Stack Overflow See other posts from Stack Overflow or by Ralkie
Published on 2010-06-16T11:05:42Z Indexed on 2010/06/16 11:32 UTC
Read the original article Hit count: 1045

There is a requirement to have not-so-trivial dynamic list, each record of which consists of several columns (texts, buttons). It should look something like:

Text11 Text12 Button1 Button2
Text21 Text22 Button1 Button2
...

At first obvious way to accomplish that seemed to be TableLayout. I was expecting to have layout/styling data specified in res/layout/*.xml and to populate it with some dataset from java code (as with ListView, for which its possible to specify TextView of item in *.xml and bind it to some array using ArrayAdapter). But after playing for a while, all I found to be possible is fully populating TableLayout programatically. Still, creating TableRow by TableRow and setting layout attributes directly in java code doesn't seem elegant enough.

So the questions are:

  1. Am I at the right path? Is TableLayout really best View to accomplish that? Maybe it's more appropriate to extend ListView or something else to meet such requirements?

  2. Is it possible to have TableLayout/TableRow template specified in *.xml and data bound to this template in java side?

© Stack Overflow or respective owner

Related posts about android

Related posts about listview