public class ShowAdapter extends RecyclerView.Adapter {
Context context;
RecyBean showBean;
XbannerBean xbannerBean;
int XbannerType=0;
int RxxpType=1;
int MlssType=2;
int PzshType=3;
private RecyBean.ResultBean.RxxpBean rxxpBean;
private RecyBean.ResultBean.MlssBean mlssBean;
private RecyBean.ResultBean.PzshBean pzshBean;
public ShowAdapter(Context context, RecyBean showBean, XbannerBean xbannerBean) {
this.context = context;
this.showBean = showBean;
this.xbannerBean = xbannerBean;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
if(i==XbannerType){
View viewXbanner = LayoutInflater.from(context).inflate(R.layout.xbanner_show, viewGroup, false);
return new ViewHolderXbanner(viewXbanner);
}else if(i==RxxpType){
View viewRxxp = LayoutInflater.from(context).inflate(R.layout.rxxp_show, viewGroup, false);
return new ViewHolderRxxp(viewRxxp);
}else if(i==MlssType){
View viewMlss = LayoutInflater.from(context).inflate(R.layout.mlss_show, viewGroup, false);
return new ViewHolderMlss(viewMlss);
}else{
View viewPzsh = LayoutInflater.from(context).inflate(R.layout.pzsh_show, viewGroup, false);
return new ViewHolderPzsh(viewPzsh);
}
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, final int i) {
if (i==XbannerType){
ViewHolderXbanner viewHolderXbanner= (ViewHolderXbanner) viewHolder;
if (viewHolderXbanner.xBanner.getRealCount()<=0){
viewHolderXbanner.xBanner.setData(xbannerBean.getResult(),null);
}
viewHolderXbanner.xBanner.setmAdapter(new XBanner.XBannerAdapter() {
@Override
public void loadBanner(XBanner banner, View view, int position) {
Glide.with(context).load(xbannerBean.getResult().get(position).getImageUrl()).into((ImageView) view);
}
});
viewHolderXbanner.xBanner.setOnItemClickListener(new XBanner.OnItemClickListener() {
@Override
public void onItemClick(XBanner banner, int position) {
Intent intent = new Intent(context, Main2Activity.class);
context.startActivity(intent);
}
});
}else if (i==RxxpType){
ViewHolderRxxp viewHolderRxxp= (ViewHolderRxxp) viewHolder;
rxxpBean = showBean.getResult().getRxxp();
viewHolderRxxp.rxxpt.setText(rxxpBean.getName());
//布局管理器
LinearLayoutManager rxxpManager = new LinearLayoutManager(context);
rxxpManager.setOrientation(LinearLayoutManager.HORIZONTAL);
viewHolderRxxp.rxxpr.setLayoutManager(rxxpManager);
//创建子适配器
RxxpAdapter rxxpAdapter = new RxxpAdapter(rxxpBean,context);
viewHolderRxxp.rxxpr.setAdapter(rxxpAdapter);
rxxpAdapter.setOnclick(new RxxpAdapter.onClick() {
@Override
public void onclick() {
Intent intent = new Intent(context, Main2Activity.class);
context.startActivity(intent);
}
});
}else if (i==MlssType){
ViewHolderMlss viewHolderMlss= (ViewHolderMlss) viewHolder;
mlssBean = showBean.getResult().getMlss();
viewHolderMlss.mlsst.setText(mlssBean.getName());
//布局管理器
GridLayoutManager mlssManager = new GridLayoutManager(context, 2);
viewHolderMlss.mlssr.setLayoutManager(mlssManager);
//创建子适配器
MlssAdapter mlssAdapter = new MlssAdapter(mlssBean,context);
viewHolderMlss.mlssr.setAdapter(mlssAdapter);
mlssAdapter.setOnclick(new MlssAdapter.onClick(){
@Override
public void onclick() {
Intent intent = new Intent(context, Main2Activity.class);
context.startActivity(intent);
}
});
}else{
ViewHolderPzsh viewHolderPzsh= (ViewHolderPzsh) viewHolder;
pzshBean = showBean.getResult().getPzsh();
viewHolderPzsh.pzsht.setText(pzshBean.getName());
//布局管理器
LinearLayoutManager pzshManager = new LinearLayoutManager(context);
pzshManager.setOrientation(LinearLayoutManager.VERTICAL);
viewHolderPzsh.pzshr.setLayoutManager(pzshManager);
//创建子适配器
PzshAdapter pzshAdapter = new PzshAdapter(pzshBean, context);
viewHolderPzsh.pzshr.setAdapter(pzshAdapter);
pzshAdapter.setOnclick(new PzshAdapter.onClick() {
@Override
public void onclick() {
Intent intent = new Intent(context, Main2Activity.class);
context.startActivity(intent);
}
});
}
}
@Override
public int getItemCount() {
return 4;
}
@Override
public int getItemViewType(int position) {
if (position==0){
return XbannerType;
}else if (position==1){
return RxxpType;
}else if (position==2){
return MlssType;
}else{
return PzshType;
}
}
private class ViewHolderXbanner extends RecyclerView.ViewHolder {
private final XBanner xBanner;
public ViewHolderXbanner(View viewXbanner) {
super(viewXbanner);
xBanner = itemView.findViewById(R.id.xbanner);
}
}
private class ViewHolderRxxp extends RecyclerView.ViewHolder {
private final RecyclerView rxxpr;
private final TextView rxxpt;
public ViewHolderRxxp(View viewRxxp) {
super(viewRxxp);
rxxpt = itemView.findViewById(R.id.text_rxxp);
rxxpr = itemView.findViewById(R.id.recy_rxxp);
}
}
private class ViewHolderMlss extends RecyclerView.ViewHolder {
private final TextView mlsst;
private final RecyclerView mlssr;
public ViewHolderMlss(View viewMlss) {
super(viewMlss);
mlsst = itemView.findViewById(R.id.text_mlss);
mlssr = itemView.findViewById(R.id.recy_mlss);
}
}
private class ViewHolderPzsh extends RecyclerView.ViewHolder {
private final TextView pzsht;
private final RecyclerView pzshr;
public ViewHolderPzsh(View viewPzsh) {
super(viewPzsh);
pzsht = itemView.findViewById(R.id.text_pzsh);
pzshr = itemView.findViewById(R.id.recy_pzsh);
}
}
}