RecyclerView implementation of traex's ExpandableLayout.
repositories {
google()
jcenter()
}
dependencies {
compile "com.hendraanggrian.recyclerview:recyclerview-expandable:$version"
}
Create a row of your RecyclerView:
<com.hendraanggrian.recyclerview.widget.ExpandableItem
android:id="@+id/row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:duration="500"
app:layoutHeader="@layout/view_content"
app:layoutContent="@layout/view_header"/>
Create your adapter, which must extend ExpandableRecyclerView.Adapter
:
public class MyAdapter extends ExpandableRecyclerView.Adapter<MyAdapter.ViewHolder> {
public MyAdapter(LinearLayoutManager layout) {
super(layout);
...
}
@Override
public void onBindViewHolder(MyAdapter.ViewHolder holder, final int position) {
super.onBindViewHolder(holder, position);
...
}
public static class ViewHolder extends RecyclerView.ViewHolder {
...
}
}
Have an ExpandableRecyclerView
somewhere in your app, regular RecyclerView
works too.
<com.hendraanggrian.recyclerview.widget.ExpandableRecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Then pass LinearLayoutManager to the adapter:
LinearLayoutManager layout = new LinearLayoutManager(this);
RecyclerView.Adapter adapter = new MyAdapter(layout);
recyclerView.setLayoutManager(layout);
recyclerView.setAdapter(adapter);