修改名称。
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
package com.xscm.modulemain.adapter;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.xscm.modulemain.R;
|
||||
import com.xscm.moduleutil.bean.GiftBoxRecordBean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GiftBoxAdapter extends RecyclerView.Adapter<GiftBoxAdapter.GiftBoxViewHolder> {
|
||||
|
||||
private static final int TYPE_HEADER = 0;
|
||||
private static final int TYPE_ITEM = 1;
|
||||
|
||||
private List<GiftBoxRecordBean> giftBoxList;
|
||||
|
||||
public GiftBoxAdapter(List<GiftBoxRecordBean> giftBoxList) {
|
||||
this.giftBoxList = giftBoxList;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public GiftBoxViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view;
|
||||
if (viewType == TYPE_HEADER) {
|
||||
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_gift_box, parent, false);
|
||||
// 设置标题可见
|
||||
view.findViewById(R.id.tv_label_time).setVisibility(View.VISIBLE);
|
||||
view.findViewById(R.id.tv_label_gift_name).setVisibility(View.VISIBLE);
|
||||
view.findViewById(R.id.tv_label_obtain).setVisibility(View.VISIBLE);
|
||||
// 隐藏数据项
|
||||
view.findViewById(R.id.tv_time).setVisibility(View.GONE);
|
||||
view.findViewById(R.id.tv_gift_name).setVisibility(View.GONE);
|
||||
view.findViewById(R.id.tv_obtain).setVisibility(View.GONE);
|
||||
} else {
|
||||
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_gift_box, parent, false);
|
||||
// 设置数据项可见
|
||||
view.findViewById(R.id.tv_time).setVisibility(View.VISIBLE);
|
||||
view.findViewById(R.id.tv_gift_name).setVisibility(View.VISIBLE);
|
||||
view.findViewById(R.id.tv_obtain).setVisibility(View.VISIBLE);
|
||||
// 隐藏标题项
|
||||
view.findViewById(R.id.tv_label_time).setVisibility(View.GONE);
|
||||
view.findViewById(R.id.tv_label_gift_name).setVisibility(View.GONE);
|
||||
view.findViewById(R.id.tv_label_obtain).setVisibility(View.GONE);
|
||||
}
|
||||
return new GiftBoxViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull GiftBoxViewHolder holder, int position) {
|
||||
if (position == 0) {
|
||||
// 设置标题文本
|
||||
holder.tvLabelTime.setText("时间");
|
||||
holder.tvLabelGiftName.setText("礼盒名称");
|
||||
holder.tvLabelObtain.setText("获取");
|
||||
} else {
|
||||
GiftBoxRecordBean giftBox = giftBoxList.get(position - 1);
|
||||
holder.tvTime.setText(giftBox.getCreatetime());
|
||||
holder.tvGiftName.setText(giftBox.getGift_bag_name());
|
||||
holder.tvObtain.setText(giftBox.getGift_name());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return giftBoxList.size() + 1; // 加上标题项
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return position == 0 ? TYPE_HEADER : TYPE_ITEM;
|
||||
}
|
||||
|
||||
static class GiftBoxViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView tvLabelTime;
|
||||
TextView tvLabelGiftName;
|
||||
TextView tvLabelObtain;
|
||||
TextView tvTime;
|
||||
TextView tvGiftName;
|
||||
TextView tvObtain;
|
||||
|
||||
GiftBoxViewHolder(View view) {
|
||||
super(view);
|
||||
tvLabelTime = view.findViewById(R.id.tv_label_time);
|
||||
tvLabelGiftName = view.findViewById(R.id.tv_label_gift_name);
|
||||
tvLabelObtain = view.findViewById(R.id.tv_label_obtain);
|
||||
tvTime = view.findViewById(R.id.tv_time);
|
||||
tvGiftName = view.findViewById(R.id.tv_gift_name);
|
||||
tvObtain = view.findViewById(R.id.tv_obtain);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user