Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8710837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:43:37+00:00 2026-06-13T04:43:37+00:00

I have a list of items loaded from a web service JSON. Each of

  • 0

I have a list of items loaded from a web service JSON. Each of these items has it’s own list of sub-items. Each item has numerous text views. The number of subitems varies dynamically, and consists of multiple textviews. There are at times dozens of items with potentially hundreds of subitems. I want all the information visible all the time, i.e. I do not actually need the “expandable” part of the expandable listview but it seemed the easiest way to get the children and group layout.

Item1
  sub item 1
  sub item 2

Item 2
  sub item 1
  sub item 2
  sub item 3

etc

I have currently implemented an expandable listview and forced the groups to always be expanded. This works, however it is very slow to scroll, not only on the emulator but on my galaxy s2.
I am wondering if there is a better way to achieve this?
I considered a single list view and concatenating the strings in the subitems into a single text view but think that this will not be aesthetically pleasing and I won’t be able to get the layout I want.
I wondered if there is a way to override the listview adapted so that one of the items is an array itself of other items. The adapter could iterate over that array and create new textviews on the fly. I suppose this is what the expandable list view is doing anyway so perhaps this would end up with just as much lag scrolling.

Any help greatly appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:43:38+00:00Added an answer on June 13, 2026 at 4:43 am

    You can achieve that with ListView and custom adapter class.

    Notice that adapter has methods int getViewTypeCount() and int getItemViewType(int position) which you can overwrite.

    look at sample implemation for dataset in Map of lists

    public abstract class ExampleMapAdapter<V extends Map<?, ? extends List<?>>> extends BaseAdapter {
    
        public static final int VIEW_TYPE_HEADER = 0;
        public static final int VIEW_TYPE_LISTITEM = 1;
    
        protected V data;
        protected int[] sectionsStart;
        protected Object[] sections;
        protected int count;
    
        public ExampleMapAdapter(V data) {
            this.data = data;
            onSetData();
        }
    
        @Override
        public int getCount() {
            return count;
        }
    
        @Override
        public Object getItem(int position) {
            int sectionIndex = getSectionForPosition(position);
            int innerIndex = position - sectionsStart[sectionIndex];
            if(innerIndex == 0) { //head
                return sections[sectionIndex];
            }
            else { //values
                return data.get(sections[sectionIndex]).get(innerIndex - 1);
            }
        }
    
        @Override
        public long getItemId(int position) {
            return position;
        }
    
        @Override
        public int getViewTypeCount() {
            return 2;
        }
    
        @Override
        public int getItemViewType(int position) {
            return Arrays.binarySearch(sectionsStart, position) < 0 ? VIEW_TYPE_LISTITEM : VIEW_TYPE_HEADER;
        }
    
        public int getPositionForSection(int section) {
            return sectionsStart[section];
        }
    
        public int getSectionForPosition(int position) {
            int section = Arrays.binarySearch(sectionsStart, position);
            return section < 0 ? -section - 2 : section;
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if(getItemViewType(position) == VIEW_TYPE_HEADER) {
                return getHeaderView(position, convertView, parent);
            }
            else {
                return getListItemView(position, convertView, parent);
            }
        }
    
        @Override
        public void notifyDataSetInvalidated() {
            data = null;
            onSetData();
            super.notifyDataSetInvalidated();
        }
    
        @Override
        public void notifyDataSetChanged() {
            onSetData();
            super.notifyDataSetChanged();
        }
    
        protected void onSetData() {
            if(data == null) {
                sectionsStart = null;
                sections = null;
                count = 0;
            }
            else {
                sectionsStart = new int[data.size()];
                sections = data.keySet().toArray(new Object[data.size()]);
                count = 0;
                int i = 0;
                for(List<?> v : data.values()) {
                    sectionsStart[i] = count;
                    i++;
                    count += 1 + v.size();
                }
            }
        }
    
        protected abstract View getHeaderView(int position, View convertView, ViewGroup parent);
    
        protected abstract View getListItemView(int position, View convertView, ViewGroup parent);
    }
    

    and usage example:

    public class ExampleActivity extends Activity {
    
        class SubItem {
            public final String text;
            public final int number;
            public final boolean checked;
            public SubItem(String text, int number, boolean checked) {
                this.text = text;
                this.number = number;
                this.checked = checked;
            }
        }
    
        //use LinkedHashMap or TreeMap as other map implementations may not keep key's order
        final Map<String, List<SubItem>> map = new LinkedHashMap<String, List<SubItem>>();
        {
            List<SubItem> list = new ArrayList<SubItem>();
            list.add(new SubItem("sub item", 1, false));
            list.add(new SubItem("sub item", 2, true));
            map.put("Item1", list);
            list = new ArrayList<SubItem>();
            list.add(new SubItem("sub item", 1, true));
            list.add(new SubItem("sub item", 2, false));
            list.add(new SubItem("sub item", 3, false));
            map.put("Item2", list);
        }
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
    
            ListView vList = new ListView(this);
            vList.setAdapter(new ExampleMapAdapter<Map<String, List<SubItem>>>(map) {
    
                @Override
                protected View getHeaderView(int position, View convertView,
                        ViewGroup parent) {
                    TextView v = convertView == null ? 
                            new TextView(parent.getContext()) : (TextView) convertView;
                    v.setText((String) getItem(position));
                    return v;
                }
    
                @Override
                protected View getListItemView(int position, View convertView,
                        ViewGroup parent) {
                    CheckBox v = convertView == null ? 
                            new CheckBox(parent.getContext()) : (CheckBox) convertView;
                    SubItem item = (SubItem) getItem(position);
                    v.setText(item.text + " " + item.number);
                    v.setChecked(item.checked);
                    return v;
                }
            });
            setContentView(vList);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page with a list of items initially loaded from a include_once('show_calendarV2.php');
I have a list of items of type ViewLookupItem which has these properties: For
I have a list of items, like a menu, where the current item has
I have a listview that probably has infinite items loaded on scrolling infinitely. Each
I have a list of items, which has two values, a name and an
In my web app, I have a list of editable objects, each with an
I have the items for a combo box being loaded from a store but
I have created a flip animation to go from a list of items to
I have a list view displaying a list of images from the web. The
I have a list view those will loaded from shared preference. when user clicks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.