1.在Adapter的默认构造方法中初始化
初始化,设置默认都展开
{
Map<Integer, Boolean> isUnfold=new HashMap<>();
for (int i = 0; i <10 ; i++) {//设置初始值,用来表示是否是打开或是关闭
isUnfold.put(i,true);
}
}
####2.在getView中 holder.ll_fangjie_dec.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos = (int) v.getTag();
isUnfold.put(pos,!isUnfold.get(pos));
notifyDataSetChanged();
LogUtils.i("pos="+pos);
}
});
if (isUnfold.get(position)){
holder.ll_content.setVisibility(View.VISIBLE);
holder.tv_unfold.setText("收起详情");
holder.iv_arrow.setImageResource(R.drawable.icon_close);
}else {
holder.ll_content.setVisibility(View.GONE);
holder.tv_unfold.setText("展开详情");
holder.iv_arrow.setImageResource(R.drawable.icon_open);
}
3.效果图