ExpandableLayout
A Expandable Linear Layout.
Setup
Dependency
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.iammert:ExpandableLayout:1.4.1'
}
Gradle
Layout
<iammert.com.expandablelib.ExpandableLayout
android:id="@+id/el"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:parentLayout="@layout/layout_parent"
app:childLayout="@layout/layout_child"/>
XML
Set renderer
expandableLayout.setRenderer(new ExpandableLayout.Renderer<FruitCategory, Fruit>() {
@Override
public void renderParent(View view, FruitCategory model, boolean isExpanded, int parentPosition) {
((TextView) view.findViewById(R.id.tvParent)).setText(model.name);
}
@Override
public void renderChild(View view, Fruit model, int parentPosition, int childPosition) {
((TextView) view.findViewById(R.id.tvChild)).setText(model.name);
}
});
Java
Set listeners
expandableLayout.setExpandListener(new ExpandCollapseListener.ExpandListener<FruitCategory>() {
@Override
public void onExpanded(int parentIndex, FruitCategory parent, View view) {
//Layout expanded
}
});
expandableLayout.setCollapseListener(new ExpandCollapseListener.CollapseListener<FruitCategory>() {
@Override
public void onCollapsed(int parentIndex, FruitCategory parent, View view) {
//Layout collapsed
}
});
Java
Add section or children
Section<FruitCategory, Fruit> section = new Section<>();
//defaut is false
section.expanded = true;
FruitCategory fruitCategory = new FruitCategory("Fruits");
Fruit fruit1 = new Fruit("Apple");
Fruit fruit2 = new Fruit("Orange");
section.parent = fruitCategory;
section.children.add(fruit1);
section.children.add(fruit2);
expandableLayout.addSection(section);
expandableLayout.addChild(fruitCategory, new Fruit("Grape"));
Java
Filter parent and children
//make your parent class filterable
class FruitCatefory implements Filterable{}
//make your child class filterable
class FruitCatefory implements Filterable{}
Java
Now, you can search in parents or children. Layout will be updated automatically.
expendableLayout.filterParent("SEARCH PARAM")
//or
expendableLayout.filterChildren("SEARCH PARAM")
Java