0

i have my expandable recyclerview set with two layouts HEADER and CHILD. Everything is working fine.

here is my screen shot.

i have used different layouts for header and child.

when the users click one header, i want my program to check if any other header is expanded. if yes it needs to be collapsed. onclicking one menu the last expanded view should collapse.

i have tried using boolean flag. can anyone please help me

4

3 回答 3

0

如果您有布尔标志,请保存展开折叠状态。您可以编写一个函数来迭代您的数据集 ArrayList 并将其设置为 false/true 并调用

adapter.notifyDatasetChanged();
于 2016-04-08T10:55:10.980 回答
0

使用 Big Nerd Ranch recycler:expand library ('com.bignerdranch.android:expandablerecyclerview:1.0.3')

在 RecyclerAdapter.Java 代码中...

 @Override
public void onParentItemClickListener(int position) {
    /**
     * @Params
     * Se comienza en -1, al clickear el primer grupo, se registra en la variable su posicion
     * al clickear el siguiente grupo, si la variable no es igual a su posicion se procede a
     * cerrar el grupo anterior.
     * */

    Object parent = mParentItemList.get(position);
    //Toast.makeText(mContext,"posicion "+String.valueOf(position),Toast.LENGTH_SHORT).show();

    if(lastExpanded == -1){
        lastExpanded = position;

    } else if(lastExpanded == position){
        lastExpanded = -1; //Reinicia Variable

        notifyItemChanged(position);
    }else{
        //Cierra grupo abierto
        int oldExpand = lastExpanded;
        Toast.makeText(mContext,"se cerro  "+String.valueOf(oldExpand),Toast.LENGTH_SHORT).show();
        lastExpanded = position;

        //Need the colapse group code

        notifyItemChanged(oldExpand);
        notifyItemChanged(position);
    }

    super.onParentItemClickListener(position);
}

单击另一个父组后,我需要如何折叠组...

如果你有解决方案,请评论我

于 2018-07-30T21:19:49.937 回答
0

如果你使用这个来创建你的可扩展部分,就像在这个例子中一样,你可以遍历你的 ExpandableContactsSection 的实例并检查标志'expanded'。

于 2016-04-08T14:00:44.733 回答