hamsterready / android-accordion-view

Simple ListView based Android AccordionView
163 stars 107 forks source link

auto collapse? #3

Closed randyarrowood closed 11 years ago

randyarrowood commented 11 years ago

what would you recommend as the easiest way to auto-collapse the sections in the accordion on launch?

hamsterready commented 11 years ago

There was quite easy way to do it. Will check in the morning and let you know.

randyarrowood commented 11 years ago

Thanks. Please let me know if you have something better than this mod to the onFinishInflate:

for (int i = 0; i < childCount; i++) {
      wrappedChildren[i] = getView(inflater, i);
      View header = getViewHeader(inflater, i);
      View footer = getViewFooter(inflater);
      final LinearLayout section = new LinearLayout(getContext());
      section.setOrientation(LinearLayout.VERTICAL);
      section.addView(header);
      section.addView(wrappedChildren[i]);
      wrappedChildren[i].setVisibility(GONE);
      section.addView(footer);

      sectionByChildId.put(children[i].getId(), section);

      addView(section);

    }
wrappedChildren[childCount-1].setVisibility(VISIBLE);
initialized = true;
hamsterready commented 11 years ago

So... sounds like there is no easy option at the moment. One need to have access to wrappedChildren[i] and at the moment there are no getters for that ;(

You could traverse what you get from getSectionById() and then find button and issue click().

hamsterready commented 11 years ago

See my last commit - now you can configure visibility by providing reference to int-array where each item represents visibility status of each section:

In main.xml:

accordion:section_visibility="@array/accordion_visibility"

In strings.xml:

<integer-array name="accordion_visibility">
    <item>1</item>
    <item>1</item>
    <item>0</item>
    <item>0</item>
    <item>0</item>
</integer-array>