android – Multi expandable recyclerview

android – Multi expandable recyclerview,第1张

概述我尝试实现我自己的多可扩展RecyclerView它工作正常一个子项目,但当我想要子项目的视图显示,但我需要多次点击它. 层次结构示例: Title1 SubTitle1 SubTitle2 SubTitle3 SubSubTitle1 SubSubTitle2Title2... 编辑:问题仅在SubTitle上显示SubSub’sItem.我想我需要通知父适配器我 我尝试实现我自己的多可扩展RecyclerVIEw它工作正常一个子项目,但当我想要子项目的视图显示,但我需要多次点击它.
层次结构示例:

Title1  SubTitle1  SubTitle2  SubTitle3    SubSubTitle1    SubSubTitle2Title2...

编辑:问题仅在SubTitle上显示SubSub’sItem.我想我需要通知父适配器我的视图已更改但我无法工作.

要做到这一点,我使用了RecyclerVIEw和itemLayout,它们也包含了RecyclerVIEw,当我点击项目时,我设置了适配器关闭了孩子的RecyclerVIEw.我使用我在这里找到的自定义linearlayoutmanager https://stackoverflow.com/a/29261667/3289338.

我的onBindVIEwHolder:

@OverrIDepublic 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    }}

和布局:

<?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>

感谢名单.

解决方法 https://github.com/itsnothingg/RecursiveRecyclerView

我为此做了一个开源.您可以轻松实现多扩展回收视图,并为每个扩展深度使用不同的布局.

总结

以上是内存溢出为你收集整理的android – Multi expandable recyclerview全部内容,希望文章能够帮你解决android – Multi expandable recyclerview所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1125530.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存