0

I want to display an ListView which should have Header/divider after the set of elements are displayed.

I want something like this

I have the set of elements in an Map like this -

Map<String,ArrayList<File>> list=new HashMap<>();

Every different element of this Map should be considered as an group. For example the first element list is Group 1 and the second element of the list is Group 2 and so on. The size of every group is not fixed it may be 10 or it may be 3 etc.

Can any one help me to achieve this.

Rajesh K
  • 683
  • 2
  • 9
  • 35
  • Consider using RecyclerView instead. – Nicolas Jan 15 '18 at 12:52
  • @NicolasMaltais Can you please explain the benefit of using RecyclerView over ListView. – Rajesh K Jan 15 '18 at 12:56
  • You get much better animations and performance, see [this](https://stackoverflow.com/a/28398488/5288316). As for making sections in RecyclerView, I recently used [this method](https://newfivefour.com/android-recyclerview-section-headers-view-types.html) and it worked. – Nicolas Jan 15 '18 at 22:36
  • @NicolasMaltais Thank You very much for the suggestion. Will surely have a look and use if possible. – Rajesh K Jan 16 '18 at 11:15
  • What do you want to do with those groups. Depending on your answer I would recommend either to use different `ViewType`s in your adapter or an [`ExpandableListView`](https://developer.android.com/reference/android/widget/ExpandableListView.html) altogether. Your data structure seems like an argument for the latter. – kalabalik Jan 16 '18 at 11:25
  • @kalabalik I want to show the groups to the user and provide the user with the option of selection. – Rajesh K Jan 16 '18 at 12:33
  • Use `ExpandableListView`. It fits your data structure such that the `String`s go into your `Group` views and your ArrayLists go into each group's child views. Dive into one or two tutorials and then come back with code and a more focussed question. – kalabalik Jan 16 '18 at 13:42
  • @kalabalik Thanks for the suggestion. Can you please tell that can the Expandable ListView items always be expanded? – Rajesh K Jan 16 '18 at 13:44
  • Yes, you can expand groups upon start and disable any collapsing mechanism. The (ListView) alternative would be to flatten your data structure to one dimension and have those objects hold a boolean, for example, so you can differentiate between view types. – kalabalik Jan 16 '18 at 14:55
  • @kalabalik Sorry for the delay in replying. Thank You very much for the suggestion. Will try and check whether that fits the situation and needs required by me. – Rajesh K Jan 19 '18 at 10:02

0 Answers0