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

Suresh Basnet
  • 147
  • 2
  • 13
  • visit this https://www.bignerdranch.com/blog/expand-a-recyclerview-in-four-steps/ –  Apr 08 '16 at 10:34

3 Answers3

0

If you have a Boolean flag so save expand collapse states. You can write a function to Iterate your data-set ArrayList and set it to false/true and call

adapter.notifyDatasetChanged();
H.T
  • 161
  • 7
0

If you use this library to create your expandable sections like in this example, you can loop through the instances of your ExpandableContactsSection and check the flag 'expanded'.

Gustavo Pagani
  • 6,583
  • 5
  • 40
  • 71
0

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

In RecyclerAdapter.Java code...

 @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);
}

I need how to collapse group after clicking another parentGroup...

If you have the solution, comment me please

Ignacio_aa
  • 318
  • 2
  • 8