tags:

views:

36

answers:

1

I have a list where i basically need a hierarchy of items. Any children of an item would be padded slightly, as to easily distinguish their parent item. How could this be achieved?

Note that i could, if needed, make each parent show no children, and then when the parent is clicked, a new list containing all of it's children is loaded. This however requires more clicking to display information than i would prefer.

Also, the items themselves will contain graphics and whatnot (to show a drag'n'drop button, etc), so it would be best if it visually appeared as if the item itself had a margin, rather than the contents of the item being padded.

Thanks to any replies!

+2  A: 

Step #1: Make sure each item in your data model can determine its depth (roots = depth of 0, children of roots = depth of 1, grandchildren of roots = depth of 2, etc.)

Step #2: In your custom ListAdapter's getView() or bindView(), do something to slide your stuff over to the right by a multiple of that position's depth, such as:

  • adjusting the left margin of your first child widget inside your row
  • putting a spacer invisible View as the left-most widget and changing its width
  • adjusting the left margin of the whole row (not sure if this will work)

Make sure that when you recycle rows, you always fix up the margin to the value for the current position.

CommonsWare
Another approach to sliding things over is to have an `ImageView` as your left-most widget in the row, and to change that `ImageView` to be something indicating the indent level. Think the hierarchy lines in a Windows-style tree view.
CommonsWare
Thanks! I didn't want to just hack something together, it's nice to hear pointers of sound methodologies :). On a side note, and forgive me if you've mentioned this somewhere, but do you have any plans of publishing any of your books? I bought them long ago, and from what i've read they're great (and your activity on here is awesome), but i really prefer reading from physical books.. getting away from the computer is nice heh. Anyway, thanks for the replies!
Lee Olayvar
@Lee - all but one of my books are in print in online bookstores, just search for the title. However, they only get updated once a year or so, compared to the digital editions.
CommonsWare
Oh nice, i didn't think they were even being printed! I actually own a subscription, but i think i'll buy the book anyway.Thanks!
Lee Olayvar