RecruitmentRecAdapter.java 3.2 KB
package com.hh.xuetubao.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hh.xuetubao.R;
import com.hh.xuetubao.bean.CompanyDetailBean;

import java.util.List;


public class RecruitmentRecAdapter extends RecyclerView.Adapter<RecruitmentRecAdapter.ViewHolder> {

    private Context context;
    private List<CompanyDetailBean.JobFunctionListBean.JobListBean> list;

    public RecruitmentRecAdapter(Context context, List<CompanyDetailBean.JobFunctionListBean.JobListBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.rv_recruiment_job, null);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {


        if (list.get(position).getJobName() != null)
            holder.job.setText(list.get(position).getJobName());
        if (list.get(position).getSalary() != null)
            holder.money.setText(list.get(position).getSalary());
        if (list.get(position).getExprience() != null)
            holder.year.setText(list.get(position).getExprience());
        if (list.get(position).getEducation() != null)
            holder.education.setText(list.get(position).getEducation());
        if (!TextUtils.isEmpty(list.get(position).getAddress())) {
            holder.address.setText(list.get(position).getAddress());
        }

        LinearLayoutManager manager = new LinearLayoutManager(context);
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        holder.recLabel.setLayoutManager(manager);

        List<CompanyDetailBean.JobFunctionListBean.JobListBean.LabelListBean> labelList = list.get(position).getLabelList();
        RecruitmentLabelAdapter adapter = new RecruitmentLabelAdapter(labelList, context);
        holder.recLabel.setAdapter(adapter);
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView job;
        private final TextView money;
        private final TextView year;
        private final TextView education;
        private final TextView address;
        private final RecyclerView recLabel;

        public ViewHolder(View itemView) {
            super(itemView);
            job = (TextView) itemView.findViewById(R.id.job);
            money = (TextView) itemView.findViewById(R.id.money);
            year = (TextView) itemView.findViewById(R.id.year);
            education = (TextView) itemView.findViewById(R.id.education);
            address = (TextView) itemView.findViewById(R.id.address);
            recLabel = (RecyclerView) itemView.findViewById(R.id.rec_label);
        }
    }

}