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

我按照这个答案创建了一个可扩展的回收器视图:https ://stackoverflow.com/a/48092441/7787266

它工作得很好,但我想要 recyclerview 的初始行为,这样当我打开应用程序时,第一个项目应该已经展开,而无需我触摸它。

4

1 回答 1

0
 expListView.collapseGroup(groupPos)

嗯……反了……

expListView.expandGroup(groupPos) 
于 2018-06-07T09:29:01.820 回答