package com.danding.yang800.Adapter;

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

import com.danding.yang800.BaseActivity;
import com.danding.yang800.MarketActivity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public abstract class MyBaseAdapter<T> extends BaseAdapter {
    public ArrayList<T> lists;
    protected LayoutInflater inflater;
    protected BaseActivity ctx;
    protected Context context;

    public MyBaseAdapter(Context context) {
        lists = new ArrayList<T>();
        this.context = context;
        inflater = LayoutInflater.from(context);
        // inflater=(LayoutInflater)
        // context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public MyBaseAdapter(BaseActivity ctx) {
        lists = new ArrayList<T>();
        this.ctx = ctx;
        inflater = LayoutInflater.from(ctx);
        // inflater=(LayoutInflater)
        // context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public void addData(T t) {
        lists.add(t);
    }

    public void delData(T t) {
        lists.remove(t);
    }

    public void delData(int index) {
        lists.remove(index);
    }

    public void addDataList(List<T> l) {
        lists.addAll(l);
    }

    public void clear() {
        lists.clear();
    }

    public ArrayList<T> getLists() {
        return lists;
    }

    public void setList(ArrayList<T> lists) {
        this.lists = lists;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return lists.size();
    }

    @Override
    public T getItem(int position) {
        // TODO Auto-generated method stub
        return lists.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

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

}
