Q:

How to Keep the ExpandableListView Checkboxes Checked States?

Currently I can check/uncheck the checkboxes by groupPosition and childPosition, and it's working fine.  I save the groupPosition and childPosition to the SQLite Database.
When I added the delete option, my checkbox checked states are off/messed up.
For example, I have the following:
Group1, 
Child1, Child2, Child3
I check all 3 of them and save the checked positions to the SQLite Database.
The checked positions would be 0,0 and 0,1 and 0,2 in the Database.
After I deleted Child1, 
Child2 becomes position 0, Child3 becomes position 1 which would mess up the checked states.
I am trying to find a way to save the group name and child name instead of the positions to the SQLite Database, then load those names in Oncrete method. 
MainActivity:
if(category_array.get(groupPosition).subcategory_array.get(childPosition).selected) {

        category_array.get(groupPosition).subcategory_array.get(childPosition).selected = false;    
        try{
            MySQLITE_DATABASE.deleteRows(groupPosition, childPosition);
           }            
        catch (Exception e) {}

 } 
  else 
 {
    category_array.get(groupPosition).subcategory_array.get(childPosition).selected = true;                 
    MySQLITE_DATABASE.addRow(groupPosition, childPosition);
 }

Adapter code:
private List<Category> mGroupCollection;

if(mGroupCollection.get(groupPosition).subcategory_array.get(childPosition).selected) {
    childHolder.checkBox.setBackgroundResource(R.drawable.checkbox_checked);

} else {
    childHolder.checkBox.setBackgroundResource(R.drawable.checkbox_unchecked);
}

Date Holder Classes:
public class Category {
public String category_name = null;
public String cat_SelectedChildCount_name;
public ArrayList<SubCategory> subcategory_array = new ArrayList<SubCategory>();
}

//==============================

public class SubCategory {
public String subcategory_name = null;
public boolean selected = false;
}

I want to save the group name and child name instead of positions to the SQLite Database and then load them in OnCreate method.
I have tried this but it is not working:
 String Group_Name = category_array.get(Integer.parseInt(groupPosition)).category_name;             
 String Child_Name = category_array.get(Integer.parseInt(groupPosition)).
                                                subcategory_array.get(Integer.parseInt(childPosition)).subcategory_name;

if(category_array.get(Group_Name).subcategory_array.get(Child_Name).selected) {
   category_array.get(Group_Name).subcategory_array.get(Child_Name).selected = false;
   MySQLITE_DATABASE.DeleteRow(Group_Name, Child_Name); 
}

else {               
    category_array.get(Group_Name).subcategory_array.get(Child_Name).selected = true;
    MySQLITE_DATABASE.AddRow(Group_Name, Child_Name); 
    }

I know that I need to change the code in the adapater, data holder classes, and mainactivity in order to make it work, but I am out of ideas.  I have been thinking and thinking, but nothing works...
Can someone please please guide me on this?
I am sorry for the long code.
Thank you and thank you.

A:

Try any of the following if it suit's your requirement.
If you want to use the position strictly (May be there is no unique option)

Keep the DB design like

| id | parent_position | child_position |

Assume you have N childs. If you delete a child (Suppose it's 0). do this

Update all the child's with (child_position = child_position - 1) whose position is greater than 
the deleted child of the parent. So the position remains unchanged.

Personally i would suggest don't use the position if a delete option is there. Option that i found, But don't know your use case

If you are loading the list from the database use the database primarykey as the key to save it in the SQLite database on selection/unselection. In this case you don't want to know the parent position as well.

