I started a three level expandable list view base on ngocchung's project:

https://github.com/ngocchung/ThreeLevelExpListView

Everything works fine, except that it's rather slow when I expand a child.
After I checked the print logs, I found everytime I expand a child with 20 items, the getChildView() will be called 20 times. While in a two-level ExpandableListView, it will be called around just 7 times because the list view can show only 5 items a time.

So I draw the conclusion that's due to view height that onMeasure restricted in CustomExpListView.java:

public class CustomExpListView extends ExpandableListView
{
    public CustomExpListView(Context context)
    {
        super(context);
    }
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
        widthMeasureSpec = MeasureSpec.makeMeasureSpec(960, MeasureSpec.AT_MOST);
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(20000, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}

The height was set to 20000 here which will load lots of items, then expand sublist will be lag because each item contains icon and two text views.
I tried to change the height from 20000 to the screen height (5 items height), it will speed up the expanding, but...the list came to an end at the 5th sub item and refuse to scroll down!
In my mind, because the child list view do not have the scroll bar, only the father can scroll, so child list views have to make itself flat, so that father scroll bar cound reach deep inside the child list.

Is it possible to link the view port of the father list with the child list? Or it there a way to limit the preloaded sub list items?
Thanks in advance!

Here's why I have to use three level list view

0

There are 0 best solutions below