package com.example.moslah_hamza.statsdemo;

import android.content.Context;
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 java.util.ArrayList;

public class ImageAdapter extends BaseAdapter {
    private Context mContext;
    private ArrayList<Categorie> categories;
    private static LayoutInflater inflater=null;


    // Constructor
    public ImageAdapter(Context c,ArrayList<Categorie> categories){
        mContext = c;
        this.categories = categories;
        inflater = ( LayoutInflater )mContext.
                getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

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

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

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

    public class Holder
    {
        TextView tv;
        ImageView img;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder=new Holder();
        View rowView;
        rowView = inflater.inflate(R.layout.grid_categories,null);
        holder.tv= (TextView) rowView.findViewById(R.id.category_grid);
        holder.img = (ImageView) rowView.findViewById(R.id.img_category_grid);

        holder.tv.setText(categories.get(position).getDescription());
        holder.img.setImageResource(R.mipmap.ic_launcher);

        return rowView;
    }
}
