i try to implements my own multi expandable RecyclerView it'w work fine for one sub-item but when i want sub-sub-item the view display but i need to click on it several times. Example of hierarchy :
Title1
SubTitle1
SubTitle2
SubTitle3
SubSubTitle1
SubSubTitle2
Title2
...
EDIT : The problem is only on the SubTitle to display SubSub'sItem. I think i need to notify parent adapter that my view changed but i doesn't work to.
To do that i used RecyclerView with itemLayout who contain too an RecyclerView and when i click on item i set adapter off the child RecyclerView. I use custom LinearLayoutManager i found here https://mcmap.net/q/103641/-nested-recycler-view-height-doesn-39-t-wrap-its-content.
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 the 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.