0

I am attempting to create a nested list view for an android app. What I essentiall want is some thing like

                     nested list entry 1
Outer List Entry1    nested list entry 2
                     nested list entry 3

                      nested list entry 1
Outer List Entry 2    nested list entry 2
                      nested list entry 3

Where I have an outer list, which has two entries, and then have a nested list view which has detailed entries (if you imagine a calendar that has days of the week as the outer list, and with each day there is a list of 0 or more appointments listed vertically as above). Further more, I want the nested list items to be clickable/highlighted in the same way a top level list would be.

Most info I find having looked for nested list views is suggestions to use ExpandableListViews - Which I implemented, but it seems like a bit ugly to use this as its clearly not the same purpose (I dont want anything expandable - everything should always be fully expanded and non-collapsible - also, couldn't find info on laying out horizontally as above rather than vertical - but I assume that is possible relatively easily?).

I also used the selected answer here: android nested listview which works ok in terms of presentation, but doesn't offer the same list scroll/highlighting/click behavior for each individual item in the nested list.

Can anyone suggest any alternatives? ever implemented a similar layout with either of the above?


UPDATE

I want the layout of the lists to actually be like the above text representation - in an attempt to clarify the layout I want, here is an image (yes, I know I should probably be downvoted for the lame screenshot of a diagram in open-office :)

enter image description here

So you can see, I actually want the screen to look like that - the parent/outer list being a list of time periods (in this case its days of the week, but it could be hours of the day etc), and for each row in that outer list, I want the inner list (appointments for that given timeslot) to appear as a nested list aligned horizontally to the parent.

Community
  • 1
  • 1
rhinds
  • 9,976
  • 13
  • 68
  • 111

2 Answers2

1

Updated answer: If you want a table then you should probably split it to Fragments. The root View should be ScrollView. The child must be horizontal LinearLayout Every next column is a Fragment. Every Fragment container should have some weight. Every Fragment's root view should be vertical LinearLayout Make sure Frament with days item has the height of exactly three "tasks" item height. Hardcode them in dimen.xml. For convinience, make every Fragment's LinearLayout extended class that can have ListAdapter set. Populate the every row based on ListAdapter. That way you can achieve a list with fixed content.

Or you can do without Fragments if you don't want to be flexible. Adding new column will be just a matter of Fragments that encapsulate the logic.

Yaroslav Mytkalyk
  • 16,950
  • 10
  • 72
  • 99
  • Thanks - Unless I have missed something, I'm not sure that's exactly what I want - its not that I want a single list with different layouts for different rows, its more that in each row of my main list, I want to have another nested listview of other details. – rhinds Jan 10 '14 at 13:12
  • @rhinds well you can achieve the look of expandable ListView using different layouts. "Header" list and below every "header" a sublist. Or maybe I don't understand what are you trying to achieve. Do you want it to look horizontal like in a question? Or was that just to show how categories are organized? – Yaroslav Mytkalyk Jan 10 '14 at 16:38
  • Ok, so I have updated the original question - yes I wanted the layout to actually be as per the original illustration, but I have added a lame screenshot to try and illustrate further - I would imagine this isn't a particularly unique layout? – rhinds Jan 10 '14 at 16:53
  • @rhinds updated the answer. Lots of code will be there and I have no time to paste snippets, just described the general idea. – Yaroslav Mytkalyk Jan 10 '14 at 17:28
1

To make ExpandableListView not collapse ,use

expandableList.setOnGroupClickListener(new OnGroupClickListener() {
  @Override
  public boolean onGroupClick(ExpandableListView parent, View v,
                              int groupPosition, long id) { 
    return true; // This way the expander cannot be collapsed
  }
});
Akhil Jain
  • 13,872
  • 15
  • 57
  • 93
  • Thanks - this is good to know - 2 follow ups: 1) can I tweak the layout so the expandable list appears horizontally as per my post? 2) Do you think this is reasonable use of expandable list? would it be bad practice (or a horrible hack)? Its not really an unusual layout, so I assume it must have been solved many times. – rhinds Jan 10 '14 at 13:14
  • ok ,so bottom line i understand is you want view to scroll horizontally, you have tried `HorizontalScrollView` – Akhil Jain Jan 10 '14 at 13:17
  • Why i would usggest you to go fo `HorizontalScrollView` would be because `ExpandableListView` do not have `android:orientation` property, see here for yourself=> http://developer.android.com/reference/android/widget/ExpandableListView.html – Akhil Jain Jan 10 '14 at 13:20
  • Its not that I want it to just be horizontal, I primarily need a list of lists layout (maybe my original illustration wasnt very clear! I have added a little to the diagram to illustrate the two lists) – rhinds Jan 10 '14 at 13:25
  • i cannot see any diagram – Akhil Jain Jan 10 '14 at 16:05
  • I just mean my textual illustration, with the outer and nested lists – rhinds Jan 10 '14 at 16:07
  • if you want list of list, go with expandable list view – Akhil Jain Jan 10 '14 at 16:09
  • Ok, thanks - and do you know if it is possible to layout an expandable list with the parent>child layout horizontally (as per text illustration in original post) – rhinds Jan 10 '14 at 16:18
  • again it will not, the `ExpandableListView` will not be horizontal, it s not designed in that way, why do not you try to do so in demo xml and also please accept the answer! – Akhil Jain Jan 10 '14 at 16:28