EventAdapter.java 1.85 KB
package com.example.martin.projetv5;

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

import java.util.ArrayList;
import java.util.List;

/**
 * Created by martin on 21/02/2017.
 */

public class EventAdapter extends BaseAdapter {
    public List<Event> mList;
    public Context mContext;
    public LayoutInflater mInflater;

    public EventAdapter(Context context, List<Event> aList) {
        mContext = context;
        mList = aList;
        mInflater = LayoutInflater.from(mContext);
    }

    public int getCount() {
        return mList.size();
    }

    public Object getItem(int position) {
        return mList.get(position);
    }

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

    public View getView(int position, View convertView, ViewGroup parent) {
        LinearLayout layoutItem;

        if (convertView == null) {
            layoutItem = (LinearLayout) mInflater.inflate(R.layout.event, parent, false);
        } else {
            layoutItem = (LinearLayout) convertView;
        }

        TextView date = (TextView) layoutItem.findViewById(R.id.date);
        TextView event = (TextView) layoutItem.findViewById(R.id.event);

        date.setText(mList.get(position).getDate());
        event.setText(mList.get(position).getEvenement());

        return layoutItem;
    }

    public interface EventAdapterListener {
        void onClickButton(Event item, int position);
    }

    private ArrayList<EventAdapterListener> mListListener = new ArrayList<EventAdapterListener>();

    public void addListener(EventAdapterListener aListener) {
        mListListener.add(aListener);
    }
}