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 7673489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:31:24+00:00 2026-05-31T16:31:24+00:00

I’m writing simple filter in Android and want to use ExpandableListAdapter with check boxes.

  • 0

I’m writing simple filter in Android and want to use ExpandableListAdapter with check boxes.

I have no problem with creating list or checking checkbox. but I really don’t know how to remember choices. After closing group and opening again or when I try to open different group checkboxes are changes.

I tried to reading on the net about that but I didn`t find how to solve my problem.

Here is my code:

public class TasksFilterDialog extends Dialog{

private static final String TAG = "Filter Dialog";
private static final String ChildID = "ChildID";
private static final String GroupID = "GroupID";

private boolean[] statusCheck;

ExpandableListView list;
SimpleExpandableListAdapter listAdapter;

public TasksFilterDialog(Context context) {
    super(context);
    statusCheck = new boolean[Tasks.Status.values().length];
    for(int i=0; i<statusCheck.length; i++)
        statusCheck[i]=true;
}


@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "Creating dialog");
    this.setContentView(R.layout.tasks_filter);
    list = (ExpandableListView)findViewById(R.id.filter_list);
    setListAdapter();                       // Setting Adapter Values to use on list
    list.setAdapter(listAdapter);           // Setting creating adapter to list
    setOnChildClickListeners();         


    Log.d(TAG, "Creating dialog successfull");
}


private void setListAdapter() {
    Log.d(TAG, "Setting list adapter");
    listAdapter = new SimpleExpandableListAdapter(this.getContext(), 
            getGroups(), 
            R.layout.tasks_filter_groups_layout,  
            new String[] {GroupID}, 
            new int[] {R.id.filter_group_text}, 
            getChilds(), 
            R.layout.tasks_filter_simple_element, 
            new String[] {ChildID}, 
            new int[] {R.id.filter_simple_element_text});

    Log.d(TAG, "Setting list adapter successfull");
}

private List<HashMap<String, String>> getGroups() {
    Log.d(TAG, "Adding groups values");
    List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
    HashMap<String, String> statusMap = new HashMap<String, String>();
    statusMap.put(GroupID, "Status");
    list.add(statusMap);
    HashMap<String, String> usersMap = new HashMap<String, String>();
    usersMap.put(GroupID, "Users");
    list.add(usersMap);
    Log.d(TAG, "Adding groups values successfull");
    return list;
}

private List<List<HashMap<String, String>>> getChilds() {
    Log.d(TAG, "Adding childs values");
    List<List<HashMap<String, String>>> list = new ArrayList<List<HashMap<String, String>>>();
    List<HashMap<String, String>> secList = new ArrayList<HashMap<String, String>>();
    HashMap<String, String> map;
    Tasks.Status status[] = Tasks.Status.values();
    for(int i=0; i<status.length; i++) {
        Log.d(TAG, "Adding child" + status[i].toString());
        map = new HashMap<String, String>();
        map.put(ChildID, status[i].toString());
        secList.add(map);
    }
    list.add(secList);
    list.add(secList);
    Log.d(TAG, "Adding childs values succesfull");
    return list;
}

private void setOnChildClickListeners() {
    list.setOnChildClickListener(new OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView list, View v,
                int group, int id, long arg4) {
            CheckBox cb = (CheckBox) v.findViewById(R.id.filter_simple_element_check);
            cb.toggle();
            switch(group){
            case 0:
                if(statusCheck[id])
                    statusCheck[id]=false;
                else
                    statusCheck[id]=true;
                break;
            case 1:
                //TODO After getting Tasks function

            }
            return false;
        }

    });

}

}

  • 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-05-31T16:31:25+00:00Added an answer on May 31, 2026 at 4:31 pm

    It depends on how much you want to engineer it. A Map> would work. The Map takes a position and gives you a set of checked children. To determine if a child is checked or not, call Map.get() on group, and then see if the set contains the id of the child.

    If you want to see if the second child of the third group is checked, you could do:

    boolean isChecked = yourMap.get(3).contains(2);
    

    To set a child checked:

    yourMap.get(groupNum).add(childNum);
    

    To set a child unchecked:

    yourMap.get(groupNum).remove(childNum);
    

    You would need to initialize the map to contain empty sets for every group to avoid NPEs, but thats easy to do when you first create the map. I’m sure you could come up with a cleaner way to do this, but its simple and it would work.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.