GridViewAdapter

留着以后备用

/**
 * Created by pig on 2017/2/7.
 */
    public class GridViewAdapter extends BaseAdapter{
    private Context context;
    private List channel_info;

    public GridViewAdapter(Context context, List channel_info) {
        this.context = context;
        this.channel_info = channel_info;
        Log.e("+++++++++++++",channel_info.get(0).getChannel_name());
    }

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

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

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
         ViewHolder viewHolder;
        if (convertView == null){
            convertView = View.inflate(context, R.layout.item_channel,null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);

        }
        else {
            viewHolder= (ViewHolder) convertView.getTag();
        }

        ResultBeanData.ResultBean.ChannelInfoBean channelInfoBean = channel_info.get(position);
        viewHolder.tvChannel.setText(channelInfoBean.getChannel_name());
        Glide.with(context)
                .load(Constants.BASE_URl_IMAGE +channelInfoBean.getImage())
                .into(viewHolder.ivChannel);
        return convertView;
    }
     class ViewHolder{
        protected ImageView ivChannel;
        protected TextView tvChannel;
        public ViewHolder(View convertView) {
            ivChannel = (ImageView) convertView.findViewById(R.id.iv_channel);
            tvChannel = (TextView) convertView.findViewById(R.id.tv_channel);
        }
    }
}

你可能感兴趣的:(GridViewAdapter)