Simply remember the last expanded group and collapse it before you
expand another group. This way you don't need a loop.
Try this:

private int currentHourPosition = -1; // initial value

            @Override
            public void onGroupExpand(int groupPosition) {
                super.onGroupExpand(groupPosition);
                if(currentHourPosition != -1 && currentHourPosition !=
groupPosition){
                        expandableListView.collapseGroup(currentHourPosition);
                }
                currentHourPosition = groupPosition;
//              expandableListView.setSelectedGroup(groupPosition);
                }


On 6 Aug., 23:08, Fabrizio Giudici <[email protected]>
wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 8/6/10 20:12 , TreKing wrote:> On Fri, Aug 6, 2010 at 12:28 PM, Fabrizio 
> Giudici
> > <[email protected]
> > <mailto:[email protected]>> wrote:
>
> >     The code below doesn't work (basically seems to do things
> >     at random).
>
> > What does "it does things at random" mean?
>
> > I would not collapse all but the last group. I would collapse them
> > all to make sure they're all the same, then expand the one you want.
> > Try that?
>
> Hmmm... the problem seems to be fixed by replacing:
>
>                     final int groupCount =expandableListView.getCount();
>
> with
>                     final int groupCount 
> =expandableListView.getExpandableListAdapter().getGroupCount();
>
> getCount() always returns a smaller number that it should be (e.g. 0
> when there is 1 item in the list). That explains the behaviour for
> which some nodes that are not the last one sometimes get expanded. I
> supposed that getCount() was equivalent to
> getExpandableListAdapter().getGroupCount(), but I'm clearly wrong.
>
> - --
> Fabrizio Giudici - Java Architect, Project Manager
> Tidalwave s.a.s. - "We make Java work. Everywhere."
> java.net/blog/fabriziogiudici -www.tidalwave.it/people
> [email protected]
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
> Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkxced4ACgkQeDweFqgUGxfsxwCgh1u+p4hZpLGoHuRWj6Mn5cdr
> s/EAoKGpW+ax54dK4BA34cuL8jKa5Dmr
> =DLp9
> -----END PGP SIGNATURE-----

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to