HomeCompanyAdapter.java 3.3 KB
package com.hh.xuetubao.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hh.xuetubao.R;
import com.hh.xuetubao.bean.CompanyBean;

import java.util.List;

public class HomeCompanyAdapter extends BaseAdapter {
    private List<CompanyBean.CompanyListBean> list;
    private Context context;

    public HomeCompanyAdapter(List<CompanyBean.CompanyListBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        if (list.size() > 3) {
            return 3;
        } else {
            return list.size();
        }
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = LayoutInflater.from(context).inflate(R.layout.lv_home_company, null);

        ImageView img = (ImageView) view.findViewById(R.id.img);
        TextView title = (TextView) view.findViewById(R.id.title);
        TextView address = (TextView) view.findViewById(R.id.address);
        TextView job = (TextView) view.findViewById(R.id.job);
        TextView count = (TextView) view.findViewById(R.id.job_count);
        RecyclerView rec = (RecyclerView) view.findViewById(R.id.list_label);
        View line = (View) view.findViewById(R.id.line);


        LinearLayoutManager manager = new LinearLayoutManager(context);
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        rec.setLayoutManager(manager);
        List<CompanyBean.CompanyListBean.IndustryListBean> industryList = list.get(position).getIndustryList();
        ListLabelAdapter adapter = new ListLabelAdapter(industryList, context);
        rec.setAdapter(adapter);


        count.setText(String.valueOf(list.get(position).getJobCount()));
        if (list.get(position).getCompanyLogo() != null)
            Glide.with(context).load(list.get(position).getCompanyLogo()).into(img);
        if (list.get(position).getCompanName() != null)
            title.setText(list.get(position).getCompanName());
        if (list.get(position).getAddress() != null)
            address.setText(list.get(position).getAddress());
        if (list.get(position).getPopularJobName() != null)
            job.setText(list.get(position).getPopularJobName());


        if (list.size() > 3) {
            if (position == 2) {
                line.setVisibility(View.GONE);
            } else {
                line.setVisibility(View.VISIBLE);
            }
        } else {
            if (position == list.size() - 1) {
                line.setVisibility(View.GONE);
            } else {
                line.setVisibility(View.VISIBLE);
            }

        }


        /*job.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
*/
        return view;
    }
}