Expand the first item of the recyclerview on startup without touching it

220 Views Asked by At
@Override
public void onBindViewHolder(SubCategoryHolder holder, final int position) {


    final boolean isExpanded = position == mExpandedPosition;
    holder.tv_hashtags.setVisibility(isExpanded ? View.VISIBLE : View.GONE);
    holder.copyButton.setVisibility(isExpanded ? View.VISIBLE : View.GONE);
    holder.instaButton.setVisibility(isExpanded ? View.VISIBLE : View.GONE);
    holder.shareButton.setVisibility(isExpanded ? View.VISIBLE : View.GONE);
    holder.favoriteButton.setVisibility(isExpanded ? View.VISIBLE: View.GONE);
    holder.itemView.setActivated(isExpanded);

    if (isExpanded) {
        previousExpandedPosition = position;
        holder.layoutToHide.setVisibility(View.GONE);
    }else{
        holder.layoutToHide.setVisibility(View.VISIBLE);
    }


    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mExpandedPosition = isExpanded ? -1 : position;
            notifyItemChanged(previousExpandedPosition);
            notifyItemChanged(position);
        }
    });
    final SubCategoryInformation current = data.get(position);
    holder.tv_hashtags.setText(current.getHashtags());
}

I followed this answer to create an expandable recyclerview: https://stackoverflow.com/a/48092441/7787266

It works perfectly but I want the recyclerview's initial behavior such that when I open the app, the first item should already be expanded without me touching it.

1

There are 1 best solutions below

0
On
 expListView.collapseGroup(groupPos)

well... the reverse one...

expListView.expandGroup(groupPos)