Search code examples
androidlistviewlistviewitem

Set dynamic height for list view which is added programatically in android


Please don't mark as duplicate this question without understanding.

I have gone through all answers which are available but none is able to resolve my issue.

Scenario: I have to add Sections with feature of expand and collapse on click, these sections are dynamic as per API response. So I have taken On xml file with below tree structure.

main.xml

LinearLayout->ScrollView->LinearLayout

Now I am adding custom xml design file in this linear layout as per response, also this response contains number of questions in each section. So for managing questions, I have taken listview in custom xml file. Now I have to show each listview in full height so only top scroll should work no any kind of scroll inside section.

I have checked some answers with common method name setListViewHeightBasedOnChildren but it is not working as listview is added run time dynamically.

So please help me for this.


Solution

  • As the number of sub lists are dynamic, you better go through the library

    You just need to add one more adapter to maintain sublists. its pretty easy to customize as well.

    https://github.com/luizgrp/SectionedRecyclerViewAdapter