package com.genlot.station.viewpagertest;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Copyright (C), 2019-2020, Genlot
 *
 * @author 詹子聪
 * @date 2020/6/23 16:00
 * Description:
 */
public class DemoAdapter extends BaseAdapter {
    private Context context;
    private List<String> stringList;

    public DemoAdapter(Context context, List<String> stringList) {
        this.context = context;
        this.stringList = stringList;
    }

    @Override
    public int getCount() {
        return stringList.size();
    }

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

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        String itemValue = stringList.get(position);

        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.view_item, null);
            holder = new Holder();
            holder.tv_item = convertView.findViewById(R.id.tv_item);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }

        holder.tv_item.setText(itemValue);
        return convertView;
    }

    private Holder holder;
    static class Holder {
        TextView tv_item;

    }
}
