[Mono-dev] Mono Android ExpandableList: Move item from a group to another

LaureneF lfaurevidal at algoria.fr
Fri Apr 5 09:38:19 UTC 2013


In my application, I have a list of rules that the user can activate or
desactivate. I want to display it in an ExpandableList with two groups:
active and disabled, and with a checkbox on every item that the user has to
check/uncheck to activate/desactivate a rule. No problem to implement the
look, but the difficult part is to move a rule from its group to the other
one when it's checked/unchecked.

Here is what I do in my Adapter:

 finalList.Add(activeList);            
 finalList.Add(disabledList);
 adapter = new RulesAdapter(this, new List<String> { "Profile's active
rules", "Profile's disabled rules" }, finalList, profileGuid);
 listView = FindViewById<ExpandableListView>(Resource.Id.rulesList);
 listView.SetAdapter(adapter);
I have tried many different ways but something is always wrong:

When I try to do it from the Activity like that:

    public void activateRule(RulesModel rule) {
        disabledList.Listes.Remove(rule);
        rule.State = ERuleActivationState.on;
        activeList.Listes.Add(rule);
        finalList.Clear();
        finalList.Add(activeList); finalList.Add(disabledList);
        adapter.children[1].Listes.Remove(rule);
        adapter.children[0].Listes.Add(rule);
        adapter.NotifyDataSetChanged();
    }

    public void desactivateRule(RulesModel rule)
    {
        activeList.Listes.Remove(rule);
        rule.State = ERuleActivationState.disabled;
        disabledList.Listes.Add(rule);
        finalList.Clear();
        finalList.Add(activeList); finalList.Add(disabledList);
        adapter.children[0].Listes.Remove(rule);
        adapter.children[1].Listes.Add(rule);
        adapter.NotifyDataSetChanged();
    }
items are duplicated in the list after the first click and then a click on
an item activates/desactivates and duplicates every items.

When I try to do it from the adapter that way:

        ruleCheck.Click += (sender, e) =>
        {
            if (ruleCheck.Checked == false)
            {
                children[groupPosition].Listes.RemoveAt(childPosition);
                item.State = ERuleActivationState.disabled;
                children[groupPosition].Listes.Add(item)
                //context.desactivateRule(item);
            }
            else
            {
                children[groupPosition].Listes.RemoveAt(childPosition);
                item.State = ERuleActivationState.on;
                children[groupPosition].Listes.Add(item)
                //context.activateRule(item);
            }


            //this.NotifyDataSetInvalidated();
            this.NotifyDataSetChanged();
It works one or two times and then I have an OutOfBondsException.

I don't know where I went wrong, if anyone has an idea...



--
View this message in context: http://mono.1490590.n4.nabble.com/Mono-Android-ExpandableList-Move-item-from-a-group-to-another-tp4659230.html
Sent from the Mono - Dev mailing list archive at Nabble.com.


More information about the Mono-devel-list mailing list