JAVA 전자상거래

package com.bawei.day6.view;
import android.content.Context; import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView;
import com.bawei.day6.R; import com.bawei.day6.model.Bean;
import com.bumptech.glide.Glide;
import java.util.List;
//설정 기 public class LtAdapter extends RecyclerView.어댑터{private List list;private Context context; private ViewHolder1 viewHolder; private View view; private ViewHolders viewHolder2;
public LtAdapter(List list, Context context) {
    this.list = list;
    this.context = context;
}

@Override
public int getItemViewType(int position) {
    if (position%2==0){
        return 0;
    }else {
        return 1;
    }
}

@Override
public int getItemCount() {
    return list.size();
}

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    if (i==0) {
            view = LayoutInflater.from(context).inflate(R.layout.one, null);
            viewHolder = new ViewHolder1(view);
        return viewHolder;
    }else if (i==1){
            view= LayoutInflater.from(context).inflate(R.layout.item,null);
            viewHolder2 = new ViewHolders(view);
        return viewHolder2;
    }

    return null;
}

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
    if (viewHolder instanceof ViewHolder1) {
        ViewHolder1 viewHolder1 = (ViewHolder1) viewHolder;
        Glide.with(context).load(list.get(i).getMasterPic()).into(viewHolder1.ima);
        viewHolder1.tv.setText(list.get(i).getCommodityName());

    }else if (viewHolder instanceof ViewHolders){
        ViewHolders viewHolder1 = (ViewHolders) viewHolder;
        Glide.with(context).load(list.get(i).getMasterPic()).into(viewHolder1.imm);
        viewHolder1.tvv.setText(list.get(i).getCommodityName());
    }

    }
public class ViewHolder1 extends RecyclerView.ViewHolder {

    private final TextView tv;
    private final ImageView ima;
    public ViewHolder1(@NonNull View itemView) {
        super(itemView);
        tv = itemView.findViewById(R.id.tv);
        ima = itemView.findViewById(R.id.ima);
    }
}
public class ViewHolders extends RecyclerView.ViewHolder{

    private final TextView tvv;
    private final ImageView imm;

    public ViewHolders(@NonNull View itemView) {
        super(itemView);
        tvv = itemView.findViewById(R.id.tvv);
        imm = itemView.findViewById(R.id.imm);
    }
}

}

좋은 웹페이지 즐겨찾기