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

  • SEARCH
  • Home
  • 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 8268683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:58:21+00:00 2026-06-08T05:58:21+00:00

My task is keep expanded/collapsed groups during filter. I write own filter, which remove

  • 0

My task is keep expanded/collapsed groups during filter. I write own filter, which remove group if group don’t have any child left. But after groups is gone filter’s text is changed and group come back, but it will be collapsed.

So I save expand/collapse states to group objects. So I just need in right moment apply these states.

There is my try:

class SubjectGroupList extends ExpandableListView implements OnGroupCollapseListener, OnGroupExpandListener{

    public SubjectGroupList(Context context) {
        super(context);
    }

    public void onGroupExpand(int groupPos) {
        SubjectGroup group = (SubjectGroup)getExpandableListAdapter().getGroup(groupPos);
        group.expanded = true;
    }

    public void onGroupCollapse(int groupPos) {
        SubjectGroup group = (SubjectGroup)getExpandableListAdapter().getGroup(groupPos);
        group.expanded = false;
    }

    @Override 
    public void onFilterComplete(int count) {
        fixCollapse();

        super.onFilterComplete(count);
    }

    private void fixCollapse() {
        Log.d("SubjectGroupList", "fix collapse");

        SubjectGroupAdapter adapter = (SubjectGroupAdapter)getExpandableListAdapter();
        int i = adapter.getGroupCount();
        while (--i >= 0)
            if (adapter.getGroup(i).expanded)
                expandGroup(i);
            else
                collapseGroup(i);
    }
}

but this don’t work at all. method onFilterComplete is never called.

I must find another way determine, when filter is apply before repainting.

Maybe anyone know? Thanks.

Edit:

My filter:

class GroupFilter extends Filter {
    private SubjectGroupAdapter adapter;

    public GroupFilter(SubjectGroupAdapter adapter) {
        this.adapter = adapter;
    }

    @Override
    protected FilterResults performFiltering(CharSequence s) {
        FilterResults result = new FilterResults();
        result.count = 0;

        ArrayList<SubjectGroup> groups = new ArrayList<SubjectGroup>();

        s = s.toString().toLowerCase();

        for (SubjectGroup group : adapter.ori) {
            SubjectGroup ng = new SubjectGroup(group.name, group.id);

            int founded = 0;
            for (SubjectItem item : group) {
                if (s == null || s.length() == 0 || item.name.toLowerCase().contains(s)) {
                    ng.add(new SubjectItem(item.name, item.id));
                    result.count++;
                    founded++;
                }
            }

            if (founded > 0)
                groups.add(ng);
        }

        result.values = groups;

        return result;
    }

    @Override
    protected void publishResults(CharSequence s, FilterResults result) {
        adapter.filter((ArrayList<SubjectGroup>) result.values);
    }
}

*And method of adapter which accept filtered data *:

protected void filter(ArrayList<SubjectGroup> groups) {
    this.groups = groups;
    notifyDataSetInvalidated();
}
  • 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-08T05:58:22+00:00Added an answer on June 8, 2026 at 5:58 am

    I founded answer.

    I can register DataSetObserver to Adapter, who listens for data changes or invalidate. So I register observer in ExpandableListView by overriding addAdapter method:

    @Override
    public void setAdapter(ExpandableListAdapter adapter) {
        adapter.registerDataSetObserver(new DataSetObserver() {
            public void onInvalidated() {
                fixCollapse();
            }
        });
    
        super.setAdapter(adapter);
    }
    

    Also I need tweak a bit Filter, because there was the mistakes.

    It work very well. I hope someone else helps my experience.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

TASK : I have an existing xml document (UTF-8) which uses xml namespaces and
Task: I have a camera mounted on the end of our assembly line, which
Here is how I usually write the compile task: <compc keep-generated-actionscript=true include-classes=Class1 Class2 com.package.Class3
I have a task, which I know how to code (in C#), but I
I have several long-running Task objects. I'd like them all to just keep running
Before using the Task Parallel Library, I have often used CorrelationManager.ActivityId to keep track
I have an org-mode task list that I keep in version control. I would
Would anyone happen to know a trick that will keep this MSBuild task from
I wrote a Python script that does some task to generate, and then keep
Task at hand — I have three versions of some code, developed by different

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.