package com.itant.joycity.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.itant.joycity.R;
import com.itant.joycity.bean.GridTextBean;
import com.itant.joycity.bean.OfficialItem;

import java.util.List;

/**
 * Created by Jason on 2016/10/6.
 * 图片列表适配器
 */
public class OfficialAdapter extends BaseAdapter {

    private List<OfficialItem> officialItems;
    private Context context;

    public void setOfficialItems(List<OfficialItem> officialItems) {
        this.officialItems = officialItems;
    }

    public OfficialAdapter() {

    }

    public OfficialAdapter(Context context, List<OfficialItem> officialItems) {
        this.officialItems = officialItems;
        this.context = context;
    }



    @Override
    public int getCount() {
        return officialItems == null ? 0 : officialItems.size();
    }

    @Override
    public Object getItem(int position) {
        return officialItems == null ? null : officialItems.get(position);
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        OfficialItem officialItem = officialItems.get(position);

        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_official, null);
            viewHolder = new ViewHolder();
            viewHolder.tv_official = (TextView) convertView.findViewById(R.id.tv_official);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tv_official.setText(officialItem.getTitle());
        return convertView;
    }

    private ViewHolder viewHolder;
    private static class ViewHolder {
        TextView tv_official;
    }
}
