android - Multi expandable recyclerview -
i try implements own multi expandable recyclerview it'w work fine 1 sub-item when want sub-sub-item view display need click on several times. example of hierarchy :
title1 subtitle1 subtitle2 subtitle3 subsubtitle1 subsubtitle2 title2 ... edit : problem on subtitle display subsub'sitem. think need notify parent adapter view changed doesn't work to.
to used recyclerview itemlayout contain recyclerview , when click on item set adapter off child recyclerview. use custom linearlayoutmanager found here https://stackoverflow.com/a/29261667/3289338.
my onbindviewholder :
@override public void onbindviewholder(final drawerviewholder holder, final int position) { if (holder.type == type_expandable_item) { final itemdrawer item; if (header) { item = itemdrawers.get(position - 1); } else { item = itemdrawers.get(position); } holder.textview.settext(item.gettitle()); holder.itemview.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if (item.isopen()) { item.setopen(false); holder.recyclerview_child.setvisibility(view.gone); notifyitemchanged(position); } else { item.setopen(true); holder.recyclerview_child.setvisibility(view.visible); holder.recyclerview_child.setadapter(new draweradapter(item.getsubitem(), drawer, fragmentmanager, false)); holder.recyclerview_child.setlayoutmanager(new mylinearlayoutmanager(holder.itemview.getcontext().getapplicationcontext())); notifyitemchanged(position); } } }); } else if (holder.type == type_simple_item) { final itemdrawer item; if (header) { item = itemdrawers.get(position - 1); } else { item = itemdrawers.get(position); } holder.itemview.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if (item.isactivity()) { holder.itemview.getcontext().startactivity(item.getactivityintent()); } else { fragmentmanager.begintransaction().replace(r.id.drawer_frame_layout, item.getfragment()).commit(); } } }); } else { //header } } and layout :
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="?attr/selectableitembackground" android:paddingbottom="8dp" android:paddingtop="8dp"> <imageview android:id="@+id/imageview_drawer_row_expandable" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingstart="16dp" android:src="@drawable/ic_drawer" /> <textview android:id="@+id/textview_drawer_row_expandable" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toendof="@id/imageview_drawer_row_expandable" android:paddingstart="12dp" android:paddingtop="4dp" android:textappearance="?android:attr/textappearancemedium" /> <imagebutton android:id="@+id/imageview_drawer_row_expandable_open" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentend="true" android:layout_centervertical="true" android:background="#00000000" android:paddingend="16dp" android:src="@android:drawable/arrow_up_float" /> </relativelayout> <android.support.v7.widget.recyclerview android:id="@+id/recyclerview_drawer_child" android:layout_width="@dimen/navigation_drawer_width" android:layout_height="match_parent" android:background="#ffffff" android:paddingstart="16dp" android:scrollbars="vertical" android:visibility="gone" /> </linearlayout> thanx.
https://github.com/itsnothingg/recursiverecyclerview
i made open source this. can implement multi-expanding recyclerview , use different layout each expanding depth.
Comments
Post a Comment