核心思想 每次点击改变show 的值 再重新渲染 但是
所以元素多了会出问题 没有处理元素隐藏后卸载了导致值不同的问题
public class VipAdapter extends RecyclerView.Adapter<VipAdapter.VipViewHolder> {
private Context mContext;
private LayoutInflater mLayoutInflater;
private int selectedAudioFilePosition;
private int show = -1;
public VipAdapter(@NonNull Context context) {
mContext=context;
mLayoutInflater= LayoutInflater.from(context);
}
@NonNull
@Override
public VipAdapter.VipViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new VipViewHolder(mLayoutInflater.inflate(R.layout.coupon_item,parent,false));
}
@Override
public void onBindViewHolder(@NonNull final VipAdapter.VipViewHolder holder, final int position) {
ViewGroup.LayoutParams layoutParams = holder.itemView.getLayoutParams();
layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
holder.mTextView.setText("迅雷白金会员");
if (position == show){
holder.cRelativeLayout.setVisibility(View.GONE);
holder.mRelativeLayout.setVisibility(View.VISIBLE);
}else{
holder.cRelativeLayout.setVisibility(View.VISIBLE);
holder.mRelativeLayout.setVisibility(View.GONE);
}
holder.swapButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
selectedAudioFilePosition = holder.getAdapterPosition();
show = selectedAudioFilePosition;
notifyDataSetChanged();
}
});
}
@Override
public int getItemCount() {
return 7;
}
public class VipViewHolder extends RecyclerView.ViewHolder{
private TextView mTextView,cTextView,aTextView;
private Button swapButton,sureButton;
private EditText input_phone;
private RelativeLayout mRelativeLayout,cRelativeLayout;
public VipViewHolder(@NonNull View itemView) {
super(itemView);
mTextView = (TextView)itemView.findViewById(R.id.thunder_id);
cTextView = (TextView)itemView.findViewById(R.id.energy_monthly);
aTextView = (TextView)itemView.findViewById(R.id.edit_phone);
swapButton=(Button)itemView.findViewById(R.id.swap);
sureButton=(Button)itemView.findViewById(R.id.sure_btn);
input_phone=(EditText)itemView.findViewById(R.id.input_phone);
mRelativeLayout=(RelativeLayout)itemView.findViewById(R.id.hide_input);
cRelativeLayout=(RelativeLayout)itemView.findViewById(R.id.show_input);
}
}
}