Suresh Basnet
Suresh Basnet

Reputation: 147

how to collapse all childviews on expandable recycler view

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

Upvotes: 0

Views: 2064

Answers (3)

Ignacio_aa
Ignacio_aa

Reputation: 318

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

Upvotes: 0

Gustavo Pagani
Gustavo Pagani

Reputation: 6988

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'.

Upvotes: 0

H.T
H.T

Reputation: 161

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();

Upvotes: 0

Related Questions